SRL Archive - Senior News and General

Concept Behind Random


WhoCares357

2008-03-12 18:38:42

Computer code is based on a conditional system. There is no way you can tell a computer to randomize something, because randomization is not logical.

So my question is this:

How would you create the illusion of a randomization? I'm not talking about any language in specific and am not asking for any technical descriptions. I'd just like to know the concept behind creating a "random" function.

Thanks.

Yakman

2008-03-12 19:44:02

most computers do it by getting a seed, then generating a sequence of random numbers, you can get a seed from the current time of the computer

i guess you could connect up a Geiger counter and a radioactive source to your computer, that would probably give random numbers

i think the seed and pseudorandom formula is the best bet

a bit of googling gave this snippet of C, appears to be the source of the standard library function rand()

int rand()
{
seed = (seed * 1103515245) +12345;
return (unsigned int)(seed / 65536) % 32768;
}

WhoCares357

2008-03-12 20:48:18

So it takes a digit from the current time and multiplies it by something, adds something, etc? Does this mean that there is a way to write a program that figures out the random and thus can produce the outcome of the random in another program?

This would be very hard, though, since you would have to be very, very accurate of the time. Of course, this is false if I misunderstood where the seed came from.

Yakman

2008-03-13 04:27:38

From: WhoCares357
Does this mean that there is a way to write a program that figures out the random and thus can produce the outcome of the random in another program?


you can if you know the seed, otherwise its very difficult
computers keep time to the millisecond, so trying to call time() at exactly the same time as the program you're targetting is very difficult, other ways of finding the seed are easier, by reverse engineering the program or something

WhoCares357

2008-03-13 06:51:10

Thanks guys. You finally cleared it up for me.