Thread: random choice

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    116

    random choice

    hello!
    i'd like to know if there's a way to choose one between two numbers.
    e.x. i have 0 and 1 and each time i want one of those two to be selected.does rand() help?
    thank you

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Try
    Code:
    int r = rand() > RAND_MAX/2;
    and remember to include
    Code:
    srand(time(0));
    early in the main function.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    116
    thanks a lot!worked just fine

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Botched random choice selection function
    By Xom in forum C++ Programming
    Replies: 3
    Last Post: 08-12-2011, 01:03 PM
  2. choice error
    By DarkAlex in forum C++ Programming
    Replies: 9
    Last Post: 11-10-2008, 09:59 PM
  3. Need help making a choice
    By PJYelton in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 01-09-2003, 03:05 PM
  4. Os of Choice
    By Fordy in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 09-26-2001, 08:27 AM