Skip to main content
gamedev.net
🔒 Locked

random function

Started by unknownnick Nov 20, 2003 at 8:41 AM 4 replies 700+ views
Original Post
unknownnick
unknownnick
Hy! I think this is the right place for this... Is it possible that rand function would return the same value all over again (let''s say 100 or 1000 or 1000000 times in a row)? If it would be totaly random, this would be possible (even to ALWAYS return the same value ), but they aren''t 100% random (or are they), so how big the possibility is, to get the sam result. Thanks for the answer
dopeflow
dopeflow
If your rand is based on the same seed, you will get the same values. Otherwise, I highly doubt you will get the same values 1000 times in a row...
unknownnick
unknownnick
Yes, I seed the function when I start the program (and that's the only time), and then start to "getting interested in" the results

[edited by - unknownnick on November 20, 2003 9:48:22 AM]
unknownnick
unknownnick
Tanks for the answer.

I did some tests to see how often do they repeat. And they did 6 times in 64000 rand() calls, 12 times in 128000 calls (and so on).

And that''s the randomness
Thr33d
Thr33d
[rant, rave, jabber]
If you''re looking for a larger period (that''s what it''s called - the gap between the numbers repeating)
I''d check out the mersenne twister

If you''re wondering what the chances of rand returning a number x number of times in a row
(like say... 5, so "what are the chances rand will return 5, four times in a row?" eg. 5, 5, 5, 5, (some other number) ) Umm, you could figure out what the chances *should* be (I think the chances would be 1 in 2^128 times...no? yes? so the chance of any number given 4 times in a row would be... 1 in 2^96? I think... not sure.) But to really know, you''d have to analize the actual rand function (it''s just a function - pure math.)


If you''re wanting to get the same *sequence* of random numbers, at two different times, then yeah - you''ll want to just seed it with the same value each time.
(The seed determines all the values that follow. Unfortunately, I don''t think there are all that many different seeds (not sure).) Let''s think of the best possible case:
If the RNG outputs 32 bits, the longest period possible is 2^32.
*IF* however, it''s period actually is 2^32, all values would be used, and it would loop. All seed would be part of the same, exact sequence.
I''m guessing such is not the case for rand, (and I''m pretty sure it''s not.) But hey - you might have something like a 1 in 65536 chace of seeding into the same sequence.

Which brings up another point:
If your first seed was 0, and the next number generated (from seed = 0) was 13486. But your second seed value choice happened to also be 13486, the second sequence would be identical to the first, except offset by 1.

(Now that I''ve set up my smoke-and-mirrors(tm) I''ll sit back and watch the kiddies run around falling over each other)
[/rant, rave, jabber]

Really though, if you got your answer (already) - cool. If not, I''m not sure exactly which of these your question was.
I''m kinda thinking this was one of those quest-for-knowledge type things, which is why I gave all the info I did.
If you want more, just holler!

-Michael





Current Projects:
|
+-/Heightmap Shadows Calculations
| /Page 1\---/Page 2\
|
+-/Normal Map->Heightmap Converter
+-/2d Images->3d Object Utility
+-/(future)Simple Terrain Engine w/Collision Detection
+-/(future)Character animation and model loading
:
:
(to be continued)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.