Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random Numbers
#21
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.......
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#22
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
Reply
#23
i sent in a older version i forgot to save the newer 1 Tongue
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
very F***ing song remains the same
To everyone who sucks-up for the fame
Out of strength you know we speak the truth
Every trend that dies is living proof

MasterMinds Software
Reply
#24
Quote:i sent in a older version i forgot to save the newer 1 Tongue
try this 1 instead

This one's better, but still leaves gaps that don't get filled.

Thanks
Reply
#25
it filled every space for me?
very F***ing song remains the same
To everyone who sucks-up for the fame
Out of strength you know we speak the truth
Every trend that dies is living proof

MasterMinds Software
Reply
#26
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
Reply
#27
Quote:very strange to get different output on differene machines??!!

That's what makes it random! :rotfl:
Reply
#28
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.
very F***ing song remains the same
To everyone who sucks-up for the fame
Out of strength you know we speak the truth
Every trend that dies is living proof

MasterMinds Software
Reply
#29
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!"
earn.
Reply
#30
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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)