Click to See Complete Forum and Search --> : random number in C


Squirlenutz
10-14-2007, 08:31 PM
I wrote a little program for a friend of mine that will randomly display a new guitar chord in intervals of the user's choosing. The only issue with it is that the random function produces the same exact "random" results every time the program is run. Right now I'm doing rand()%20. Any other way of doing this that will produce truly random numbers?

Strogian
10-14-2007, 10:13 PM
you need to seed the rng first. Customary is to do something like srand(time()) or however you get the time... basically just call srand with a number that changes each run.

richardginn
10-15-2007, 09:21 AM
http://www.phanderson.com/C/random.html

http://www.jb.man.ac.uk/~slowe/cpp/srand.html

http://www.cprogramming.com/tutorial/random.html

Squirlenutz
10-15-2007, 07:20 PM
awesome, thank you very much