Random Numbers - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QbasicNews.Com (http://qbasicnews.com/newforum/forum-3.html) +--- Forum: Challenges (http://qbasicnews.com/newforum/forum-10.html) +--- Thread: Random Numbers (/thread-757.html) |
yeah - Agamemnus - 05-14-2003 i think the most basic test is to see whether your random number generator will create an obvious pattern using pset(random x, random y) on the screen and it is ****OBVIOUS**** qb's rnd doesn't pass the most basic rnd test....... Re: This 1 should - Mango - 05-14-2003 Quote:I didn't have time to see how long it takes for a 'pattern' to form... but it seems pretty 'random' and on speed test's it was as fast as qb's RND def. fast code...not quite random though. My modification demonstrates this. Your Function would work well when you just want a number fast...and it doesn't have to be strictly "random" Thanks for the code. Code: DECLARE FUNCTION Rand% (Min%, Max%) oopsy - BinarySHOCK - 05-14-2003 i sent in a older version i forgot to save the newer 1 try this 1 instead DECLARE FUNCTION Rand% (Min%, Max%) SCREEN 11 DO PSET (Rand(0, 640), Rand(0, 480)), 2 LOOP DEFINT A-Z FUNCTION Rand (Min, Max) STATIC Cnt AS LONG, Cnt2 AS LONG, LastMin, LastMax STATIC LastValue Ran = Max - Min Cnt = (Cnt + (LastMin + LastMax)) AND 32767 Cnt2 = (Cnt2 + ((Cnt MOD (Max + Min)))) AND 32767 D& = ((Cnt + Cnt2) XOR (Ran + Min)) D2 = (D& + LastValue) MOD (Ran + 1) + Min Rand = D2 LastValue = D2 LastMin = Min LastMax = Max END FUNCTION Re: oopsy - Mango - 05-14-2003 Quote:i sent in a older version i forgot to save the newer 1 This one's better, but still leaves gaps that don't get filled. Thanks You sure? - BinarySHOCK - 05-15-2003 it filled every space for me? Re: You sure? - Mango - 05-15-2003 Quote:it filled every space for me? That's odd...it leaves gaps on my machine. Running it this way, it stops changing after the counter gets to 500 (=500,000 cycles), and still has gaps. very strange to get different output on differene machines??!! Code: 'binarySHOCK's code Random Numbers - oracle - 05-15-2003 Quote:very strange to get different output on differene machines??!! That's what makes it random! :rotfl: Random Numbers - BinarySHOCK - 05-15-2003 hmm yes this is very strange, how long are you waiting b4 you close the program? it seems to take around 13-15 seconds b4 it hits all the gaps over here. Random Numbers - seph - 05-23-2003 Got one! Code: PRINT "Go ask the nearest person for a random number." Tell them that if they do it, you will give them money. When they tell you, run like hell. And now you have your random number!" Random Numbers - oracle - 05-23-2003 Now this may be just me rambling on, but here is a brainstorm: I heard once from someone that the most random thing you are likely to be able to get is the background noise on the radio/tv etc coming from the cosmos. So, my plan is, why doesn't someone make a recording of background noise, and get a program to sample part of the noise when a random number is needed? I have no idea how you would go about doing this but since you can put music files into QB, and I have seen a program that outputs waves on the screen based on the sound, it should be possible. |