# Thread: Old pseudo random number generator

1. ## Old pseudo random number generator

This is an old pseudo random number generator in basic language in the book:
Tandy/Radio Shack Book:: Basic Software Library - Volume 2 (1976)(Scientific Research Inst)
page 389
https://archive.org/details/Basic_So..._Research_Inst
all the 8 volumes can be downloaded free here:
https://archive.org/details/tandy_bo...e+Library&sin=

how to run these GWBASIC codes:
download pc-basic from: https://robhagemans.github.io/pcbasic/ a good gwbasic emulator
the program save and load basic files from C:\Users\YourUserName in windows 7. but in winxp it is in the installation folder
the random.bas code: note that ** in the book is replaced by ^
```10 REM generates random #'s 0< x <1
20 LET A=4
30 LET A=A/3
50 LET B=(A+R)^8
60 LET R=B-INT(B)
70 LET I=I+1
80 IF I>100 THEN 110
90 PRINT R;
100 GOTO 50
110 LET I=0
120 END
```
save it to C:\Users\YourUserName in windows 7, the run the pc-basic and load it Load "random.bas"
then Run

here is one possible conversion to thinbasic
```Uses "Console"

'generates random #'s 0< x <1
Dim A,B,R As Single
Dim i As Long

A=4
A=A/3
While i<100
B=(A+R)^8
R=B-Int(B)
I=I+1
PrintL Str\$(R)+"  "
Wend
WaitKey
```
this is just a showcase but there are too many goodies written for GWBasic over the time from games to math to astronomy... etc and we can use it in the modern Basic languages easily

2. Here is how the original looks and runs in Script BASIC.

```' generates random #'s 0< x <1
20 SPLIT "4,0,0" BY "," TO A,I,R
30 LET A=A/3
50 LET B=(A+R)^8
60 LET R=B-INT(B)
70 LET I=I+1
80 IF I>10 THEN GOTO 110
90 PRINT FORMAT("%g",R),"\n"
100 GOTO 50
110 LET I=0
120 END
```
jrs@jrs-laptop:~/sb/examples/test\$ scriba random.sb
0.988721
0.238686
0.296148
0.704405
0.294489
0.301148
0.937858
0.994102
0.0343257
0.241162
jrs@jrs-laptop:~/sb/examples/test\$

3. it seems every software have its own way
if we dim thinbasic variables as double then the results will be different after the 5th output from the Script BASIC
also pc-basic results have different outputs except the first output
and this is for the simple rand 1 example in the book.
the same in purebasic we define its variables as double
```OpenConsole()
Define.d A,B,R

A=4
A=A/3
While i<10
B=Pow((A+R),8)
R=B-Int(B)
PrintN(StrF(R))
i+1
Wend
PrintN("press enter To exit")
Input()
```
0.9887212515
0.2386864126
0.2961478829
0.7044042349
0.2939240634
0.1643218696
0.3101503849
0.2259250879
0.9417615533
0.7879283428

4. I love these small concise routines, I think that they're far more useful than some of the convoluted programs that get written nowadays. Here's the Basic4GL version...

```
' Generates random #'s 0< X <1

dim a#, r#, b#, i

a# = 4.0

a# = (a# / 3.0)

newNum:
b# = pow( (a# + r#), 8)
r# = b# - int(b#)
i = i + 1

if i > 100 then goto endProg
endif

printr r#
drawtext()

goto newNum

endProg:
i = 0
end
```

5. Wow!

That's not even close to what TB and SB is returning. (Basic4GL)

Script BASIC numeric variant types are long and real (double). SB does a pretty good job of the transition between them with integer and floating math.

6. I suppose they are all correct
It depends on what decimal precision program perform calculations.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•