Qbasicnews.com

Full Version: Random Numbers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6
Make a random number generator that doesn't use RND... Have Fun!
Crappy but working

Code:
```DECLARE FUNCTION MyRandom% (Bottom%, Top%) DIM SHARED seed% seed% = 0 FOR i& = 0 TO 100000    PRINT MyRandom%(0, 100); NEXT FUNCTION MyRandom% (Bottom%, Top%)    Range% = Top% - Bottom%    IF seed% < 1000 THEN seed% = 1000    value& = seed% \ 35: seed% = (value& * 37) AND 32767    t% = value& MOD Range%    MyRandom% = t% + Bottom% END FUNCTION```
Interesting... but it is a pattern. If you could make it start in the a different place that would be cool.
Code:
```DEFLNG A-Z a = TIMER FOR j = 1 to 10   M = 10000   M1 = 100   b = 7821   p1 = a \ M1   p0 = a MOD M1   q1 = B \ M1   q0 = B MOD M1   c = (((p0 * q1 + p1 * q0) MOD M1) * M1 + p0 * q0) MOD M   a = (c + 1) MOD M   g = a \ M1   PRINT g NEXT```

(QBNews, Volume 2, Number 1 - February 28, 1991)
Given a certain sequence of numbers [S], it has so far been difficult to create another two sequences [S1] and [S2] that represent the first sequence and a decoder with C being at its maximum in:

length[S] = length[S1] + length[S2] + C

Another difficult problem would be to find a sequence [S]. where sequence [S1a] and decoder [S2a] are the only two possible solutions to length[S] = length[S1] + length[S2] + C.

So, making a "true" random number sequence (one without any pattern) is really hard if not impossible. :")
I think Plasma357's works!

Edit:

Heres one that picks a number 1 through 100...
Code:
```CLS INPUT "Input max ", x a\$ = STR\$(TIMER) IF LEN(a\$) < 7 THEN a\$ = a\$ + "0" a\$ = RIGHT\$(a\$, 2) a = VAL(a\$) DO IF a > x THEN a = a - x IF a <= x THEN EXIT DO LOOP PRINT a```
Quote:So, making a "true" random number sequence (one without any pattern) is really hard if not impossible. :")

Don't crack your head, RND uses patterns too. At least in QB.
I hear that nuclear decay can produce true random numbers somehow... anybody got a nuke in their backyard? Just hook it up to a COM port and write a QB app... :wink:
Quote:I hear that nuclear decay can produce true random numbers somehow... anybody got a nuke in their backyard? Just hook it up to a COM port and write a QB app... :wink:

Nope. Nuclear decay means in itself a patterned decay.

ie: Val=Val-Val/2

BTW, val would be you elemental lifespan. Find "HalfLife" in the dictionary.