User defined seed value

This is a discussion on User defined seed value within the C Programming forums, part of the General Programming Boards category; I'm doing a homework assignment that asks the user to enter a positive interger seed value to be used for ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    2

    User defined seed value

    I'm doing a homework assignment that asks the user to enter a positive interger seed value to be used for generating a random number to be used in a two player game of rolling dice. My question is how do I go about using that entered value directly in the random number generation? I looked through the threads and FAQ already and I could not find a definite answer.

    PHP Code:
                    printf("Enter a positive integer seed value: ");
        
    scanf("%i",&seed);
        
    printf("Enter number of rolls of dice: ");
        
    scanf("%i",&num);

        ?die = 
    + ( srand(seed) % );? 

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    srand is how you "us[e] that entered value directly in the random number generation". You do srand once (once only, mind), which sets the seed for future calls of rand.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    2
    Quote Originally Posted by tabstop View Post
    srand is how you "us[e] that entered value directly in the random number generation". You do srand once (once only, mind), which sets the seed for future calls of rand.
    so...

    PHP Code:
    srand(seed)
    die = 
    + (rand(seed) %6 ); 
    is that correct?

    or would it be


    PHP Code:
    srand(seed)
    die = 
    + (rand() % ); 
    Last edited by blue5t1053; 04-01-2008 at 07:14 PM.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    rand doesn't take any arguments.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. STL Map Problem with user defined Class
    By noobcpp in forum C++ Programming
    Replies: 21
    Last Post: 07-21-2008, 12:02 PM
  2. User defined 2-D array problem
    By Turtal in forum C Programming
    Replies: 5
    Last Post: 12-15-2007, 12:23 AM
  3. Stl lists and user defined types
    By figa in forum C++ Programming
    Replies: 8
    Last Post: 03-28-2005, 11:09 AM
  4. Help! User defined functions
    By AdrenalinFlow in forum C Programming
    Replies: 3
    Last Post: 02-22-2003, 06:36 PM
  5. User Defined save file (help)
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 04-16-2002, 11:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21