Results 1 to 10 of 14

Thread: Old pseudo random number generator

Hybrid View

  1. #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
    Last edited by primo; 30-06-2018 at 17:28.

  2. #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$
    Last edited by John Spikowski; 01-07-2018 at 07:45.
    ScriptBasic Project Manager
    Project Site
    support@scriptbasic.org

  3. #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. #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
    
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Generating.Random.Numbers.png 
Views:	15 
Size:	78.6 KB 
ID:	9857  
    Operating System: Windows 10 Home 64-bit
    CPU: AMD C-70 APU 40nm Technology
    Memory: 4.00GB DDR3 @ 533MHz
    Graphics: 256MB ATI AMD Radeon HD 7290 Graphics

  5. #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.
    ScriptBasic Project Manager
    Project Site
    support@scriptbasic.org

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    51
    Posts
    8,335
    Blog Entries
    2
    Rep Power
    10
    I suppose they are all correct
    It depends on what decimal precision program perform calculations.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Similar Threads

  1. Life 3D pseudo - questions.
    By RobbeK in forum TBGL General
    Replies: 12
    Last Post: 06-11-2013, 10:25
  2. Very cool random number website with java app too
    By kryton9 in forum Math: all about
    Replies: 0
    Last Post: 17-06-2012, 00:57
  3. Random Number
    By OneHitWonder in forum thinBasic General
    Replies: 1
    Last Post: 01-07-2010, 23:45
  4. Random number
    By Michael Clease in forum thinBasic General
    Replies: 10
    Last Post: 03-06-2008, 10:08
  5. Generator of random trees
    By Petr Schreiber in forum TBGL Random Trees
    Replies: 1
    Last Post: 07-09-2006, 11:18

Posting Permissions

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