idea for random number generator...

Discuss whatever you want here--both QB and non-QB related. Anything from the DEF INT command to the meaning of life!

Moderators: Pete, Mods

Post Reply
User avatar
matt2jones
Veteran
Posts: 80
Joined: Sat Feb 19, 2005 8:29 am
Location: elsewhere
Contact:

idea for random number generator...

Post by matt2jones » Wed Mar 08, 2006 8:24 am

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
Do not mistake Apathy for feeling Content.

http://www.disjointed.cjb.net - Short Storys
http://matt2jones.deviantart.com - Random Art
http://www.freewebs.com/matt2jones - WebComic

RayBritton
Veteran
Posts: 109
Joined: Thu Feb 10, 2005 12:38 pm

Post by RayBritton » Wed Mar 08, 2006 10:53 am

makes sense, quite a good idea, could always just use PI though

User avatar
Zim
Veteran
Posts: 98
Joined: Mon Dec 05, 2005 4:31 pm
Location: Wisconsin, USA
Contact:

Post by Zim » Wed Mar 08, 2006 12:51 pm

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...
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---

User avatar
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt » Wed Mar 08, 2006 8:34 pm

You know...there are university courses that cover RNG in great detail. :) It's quite a science. :)

User avatar
matt2jones
Veteran
Posts: 80
Joined: Sat Feb 19, 2005 8:29 am
Location: elsewhere
Contact:

Post by matt2jones » Thu Mar 09, 2006 2:31 pm

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
Do not mistake Apathy for feeling Content.

http://www.disjointed.cjb.net - Short Storys
http://matt2jones.deviantart.com - Random Art
http://www.freewebs.com/matt2jones - WebComic

User avatar
Zim
Veteran
Posts: 98
Joined: Mon Dec 05, 2005 4:31 pm
Location: Wisconsin, USA
Contact:

Post by Zim » Fri Mar 10, 2006 11:35 am

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.
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---

Post Reply