#include <windows.h>
srand(GetTickCount());
[edited by - evilcrap on March 25, 2002 5:45:20 PM]
Random Number
quote: Original post by EvilCrap
#include <windows.h>
srand(GetTickCount());
thanks!, my first game done ... even if it is text only...
"Computer games don''t affect kids. I mean if Pac-Man affected us as kids, we''d all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." -Kristian Wilson, Nintendo Inc. 1989
garconbifteck: You should *not* reseed the random-number generator using srand every time you generate a new number.
For most applications it suffices to call srand once when the program starts up. For servers that runs for days or weeks you should probably call srand once every now and then (say once a day or so).
Neophyte
- Death awaits you all with nasty, big, pointy teeth. -
For most applications it suffices to call srand once when the program starts up. For servers that runs for days or weeks you should probably call srand once every now and then (say once a day or so).
Neophyte
- Death awaits you all with nasty, big, pointy teeth. -
quote: Original post by Neophyte
garconbifteck: You should *not* reseed the random-number generator using srand every time you generate a new number.
For most applications it suffices to call srand once when the program starts up. For servers that runs for days or weeks you should probably call srand once every now and then (say once a day or so).
Neophyte
- Death awaits you all with nasty, big, pointy teeth. -
What will it do? It seems to work fine and it''s hardly going to be munching memory on a text game, right?
"Computer games don''t affect kids. I mean if Pac-Man affected us as kids, we''d all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." -Kristian Wilson, Nintendo Inc. 1989
quote: Original post by garconbifteck
What will it do? It seems to work fine and it''s hardly going to be munching memory on a text game, right?
Well, here''s the secret. rand isn''t random at all. It''s technically psuedorandom, in that the sequence of numbers appears random to the untrained eye, but it''s actually very reproducible. srand sets a "seed" value from which the sequence of numbers is generated, and it''s the same every time for the same given seed. So if you constantly re-seed the generator, then you increase the probability of passing it the same number more than once which makes your app appear less random.
Which isn''t what we think you want to do.
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! | Asking Smart Questions ]
Thanks to Kylotan for the idea!
Sure it would increase the chance of it repeating, but it would probably be a very slight increase. It''s not like the same number is going to come up three times in a row. That would be like a one in a million chance... (maybe less than a million)
Massif - "It means mountain."
Massif - "It means mountain."
Massif - "It means mountain."
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement