Thread: seeding with numbers, generating with characters?

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    33

    seeding with numbers, generating with characters?

    I'm trying to make a function that will generate a tic tac toe board (and a different function will print it) using a nonnegative number seed from the user. I was thinking of doing this by taking the seed, scaling it to [1,2] and having 1 be X and 2 be O. Of course, then I'd have to send some variables with that information back to main and have a different function print it. Is this possible?

    edit:
    I was thinking something like:
    Code:
    void generateBoard(int input)
    {
       int rand;
    
       srand(input);
    
       rand = ??? 
    }
    What would I have to put in rand so that it would take the input, which is n, and then scale it to [1,2] (or something of the like), where it prints 1 as X and 2 as O, or vice versa. Or is this even possible? If not, how could I do this?

    I hope that made sense.
    Last edited by muzihc; 10-20-2008 at 10:59 PM.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    4
    try like this:

    rand = rand()%2 + 1;

    so "rand" is in scal [1 2].

    additional, u should redefine the function "void generateBoard(int input)"
    to "int generateBoard(int input)" to return the variables to main.

    ths!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doxygen failing
    By Elysia in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 04-16-2008, 01:24 PM
  2. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  3. How would I only enter numbers and not characters
    By chrismax2 in forum C++ Programming
    Replies: 5
    Last Post: 04-21-2004, 03:19 PM
  4. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  5. generating random numbers within a range
    By tucky in forum C Programming
    Replies: 3
    Last Post: 09-14-2001, 12:59 PM