# Query!

• 10-09-2002
VegasSte
Query!
I recently coded a program called find the hurkle where the program used 2 random numbers to assign the 'hurkle' a place in a 2 dimensional array, and the user had to enter numbers to guess the location of the hurkle. The program would then tell the user to either enter a higher or lower number if the guess was wrong. The only problem with this program was that the rand() function always generated the same 2 numbers when the program was run, ALWAYS!! I do not understand why a random number generator would do this! Can anyone help me with this?:confused: .
• 10-09-2002
Fordy
You need to seed the rand() function

here
• 10-09-2002
VegasSte
Cheers!
Cheers mate!
:D
• 10-10-2002
wondering
I read somewhere that the rand was made that way so that if somebody wants to test your program, they'll get the same result as you did. I hope somebody can explain this better.
• 10-11-2002
VegasSte
Quote:

I read somewhere that the rand was made that way so that if somebody wants to test your program, they'll get the same result as you did. I hope somebody can explain this better.
So do I!!:confused:
• 10-11-2002
rafe
You probably already know this but I'll pretend I'm saying something interesting anyway (-;

Random number generators aren't. What they do is generate a seemingly random sequence of numbers based upon a deterministic but difficult to predict algorithm. It's NOT like shuffling a deck of cards, it's more like having an extremely huge deck of cards (millions or billions of cards) preshuffled for you. Well, even if the deck is preshuffled you will be able to predict, at least the beginning of, the sequence eventually. So what we do is jump into this preshuffled deck at seemingly random places, i.e. difficult to predict. This furthers the illusion of randomness without doing any real shuffling, we call this jumping in point the seed.

People generally use the system timer because it's available & difficult to predict but you could use anything else availble to the computer that seems to jump unpredicatably like counting page swaps, or the rainfall in Idaho. Strictly speaking, time only increases in the computer but it will seem random enuf because: 1) How much the timer increases will be hard to predict. AND more imprtantly 2) The preshuffling at a higher points in the sequence should (if it's a good generator) bring you back to lower numbers (loop back to) relatively quickly. Therefore, in a good enuf sort of way, it will look like you're jumping into the sequence anywhere high or low.

Now the punchline... when debugging it's vitally imporant to be able to replicate errors. So with random number generators we either turn them off & generate a know sequence or jump into the preshuffled sequence at known points. And in the later case because the sequence is fully deterministic (known in advance from initial inputs) we can be sure that we hit the same problem numbers at the same place in the program. Thus allowing us to get to the problems in the program again & again. Also, if the same random# generator is used on different computers you can use the same seed & get to the same point in the preshuffle & see if or how the proggie breaks on different computers.

zzzz.....
• 10-14-2002
VegasSte
eh?:confused:
• 10-14-2002
wondering
I think they write the program without a seed, so that it is very repeatable and can be tested bit by bit, and then after everything seems to be working, they add in the seed, and hopefully it will still work, now in a truly random way.
• 10-14-2002
VegasSte
Oh...I get it now! I did not get this however:
Quote:

You probably already know this but I'll pretend I'm saying something interesting anyway (-;

Random number generators aren't. What they do is generate a seemingly random sequence of numbers based upon a deterministic but difficult to predict algorithm. It's NOT like shuffling a deck of cards, it's more like having an extremely huge deck of cards (millions or billions of cards) preshuffled for you. Well, even if the deck is preshuffled you will be able to predict, at least the beginning of, the sequence eventually. So what we do is jump into this preshuffled deck at seemingly random places, i.e. difficult to predict. This furthers the illusion of randomness without doing any real shuffling, we call this jumping in point the seed.

People generally use the system timer because it's available & difficult to predict but you could use anything else availble to the computer that seems to jump unpredicatably like counting page swaps, or the rainfall in Idaho. Strictly speaking, time only increases in the computer but it will seem random enuf because: 1) How much the timer increases will be hard to predict. AND more imprtantly 2) The preshuffling at a higher points in the sequence should (if it's a good generator) bring you back to lower numbers (loop back to) relatively quickly. Therefore, in a good enuf sort of way, it will look like you're jumping into the sequence anywhere high or low.

Now the punchline... when debugging it's vitally imporant to be able to replicate errors. So with random number generators we either turn them off & generate a know sequence or jump into the preshuffled sequence at known points. And in the later case because the sequence is fully deterministic (known in advance from initial inputs) we can be sure that we hit the same problem numbers at the same place in the program. Thus allowing us to get to the problems in the program again & again. Also, if the same random# generator is used on different computers you can use the same seed & get to the same point in the preshuffle & see if or how the proggie breaks on different computers.

:D
• 10-14-2002
quzah
What they mean to say is that nothing is truely random. It's based on some nifty mathmatical formulae to simulate random number ranges. However, it isn't purely random.

Quzah.
• 10-14-2002
VegasSte
That was a lot easier to digest than the story!!:cool:
• 10-14-2002
rafe
OK OK, lesson learned. I won't make any more of these posts... sorry.
• 10-15-2002
VegasSte
:D