Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

FPprng

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • FPprng

    Algorithm to generate pseudo random numbers in (0,1)
    Discussion here https://forum.powerbasic.com/forum/u...nerator-fpprng

    Code:
    'PBCC FPprng By Ribeiro Alvo 2019
    FUNCTION PBMAIN
     LOCAL h,s,x AS EXT
     LOCAL r AS DWORD
    
    '  Seed 32 bit
       ! rdtsc
       ! mov r, eax
       s=(r+1)/(2^32+1)
    
    '  Floating Point pseudo random number generator
       DO
        h+=1
        x=FRAC((s+x)*(s+h))
        PRINT FORMAT$(x,"#.##############")
       LOOP UNTIL WAITKEY$=$ESC
    
    END FUNCTION
    Last edited by Ribeiro Alvo; 11 May 2019, 03:46 PM. Reason: Cleaning of residual variables
Working...
X