Page 1 of 1

idea for random number generator...

Posted: Wed Mar 08, 2006 8:24 am
by matt2jones
Take any number that isn't a perfect square (this will be the seed),

Calculate the first digit of it's square root in the base where 0 is the minimum and the base-1 is the maximum number the random number generator can return, and return it as the generated random number.

The next time it's called calculate the next digit, etc.

The square root of any number that isn't a perfect square is an infinite, non-repeating, decimal, so it should be thoroughly random, and should never wrap.

Sound Good?

matt

Posted: Wed Mar 08, 2006 10:53 am
by RayBritton
makes sense, quite a good idea, could always just use PI though

Posted: Wed Mar 08, 2006 12:51 pm
by Zim
So the random sequence is the digits of the root? Ok. that's good, but as you need more and more digits it will become harder and harder to compute them. Might get kinda slow...

Posted: Wed Mar 08, 2006 8:34 pm
by Nodtveidt
You know...there are university courses that cover RNG in great detail. :) It's quite a science. :)

Posted: Thu Mar 09, 2006 2:31 pm
by matt2jones
So the random sequence is the digits of the root? Ok. that's good, but as you need more and more digits it will become harder and harder to compute them. Might get kinda slow...
Naw, there's an algorithm for getting it digit by digit I saw somewhere, like long division, so you'd just need to store around two numbers to be able to work out next in the sequence, and then you replace those two and repeat it, so you're doing the same number of calculations, with the same sized numbers, each time...

Nek: True... But what's the point in learning how something's done, if you can balls it up for yourself? :wink:

matt

Posted: Fri Mar 10, 2006 11:35 am
by Zim
I think there's a little more to it than that, maybe not. I'd like to see the algorithm. Maybe it's easier with rational numbers, but with irrational numbers like pi and sqr(2), it takes real computing power to get further and further out. That's why it's such a big deal to compute millions of digits of pi. Otherwise, anyone could do it.