Qbasicnews.com
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)

Pages: 1 2 3 4 5 6


Random Numbers - whitetiger0990 - 05-03-2003

Make a random number generator that doesn't use RND... Have Fun!


Random Numbers - na_th_an - 05-03-2003

Crappy but working Wink

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



Random Numbers - whitetiger0990 - 05-03-2003

Interesting... but it is a pattern. If you could make it start in the a different place that would be cool.


Random Numbers - Plasma - 05-03-2003

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)
Tongue


Random Numbers - Agamemnus - 05-03-2003

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. :")


Random Numbers - whitetiger0990 - 05-03-2003

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



Random Numbers - Hexadecimal Disaster - 05-03-2003

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.


Random Numbers - DrV - 05-04-2003

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:


Random Numbers - relsoft - 05-05-2003

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.


Random Numbers - DrV - 05-06-2003

Whoops... radioactive decay, not nuke.

see http://www.nea.fr/abs/html/nesc0843.html