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.......
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%)
DEFINT A-Z
SCREEN 11
'INPUT "input x,y "; x, y
x = 640 'looks good when x=y, but not good with other cases!!!
y = 480
DO
PSET (Rand(0, x), Rand(0, y))
LOOP UNTIL INKEY$ <> ""
END
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 + (Max + Min)))) AND 32767
D& = ((Cnt + Cnt2) + (Ran + Min))
D2 = (D& + LastValue) MOD (Ran + 1) + Min
Rand = D2
LastValue = D2
LastMin = Min
LastMax = Max
END FUNCTION
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
Quote:i sent in a older version i forgot to save the newer 1
try this 1 instead
This one's better, but still leaves gaps that don't get filled.
Thanks
it filled every space for me?
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
DECLARE FUNCTION Rand% (Min%, Max%)
SCREEN 11
DO
FOR q = 1 TO 1000
PSET (Rand(0, 640), Rand(0, 480)), 2
NEXT q
t = t + 1
LOCATE 1, 1: PRINT t
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
Quote:very strange to get different output on differene machines??!!
That's what makes it random! :rotfl:
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.
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.