asm .members

General FreeBASIC programming questions.
dafhi
Posts: 1361
Joined: Jun 04, 2005 9:51

Re: asm .members

Postby dafhi » Sep 01, 2018 11:11

Melgo from CAcert

update 5: seems to work now

Code: Select all

type tMelgo '' random number generator - http://www.number.com.pt/Melgo.html
   
    declare operator    cast as ulong
    declare operator    cast as string
    declare constructor
   
    declare sub         sched_new
   
    as ushort           a,b,c,d = 2^13, n = -1
    as ulongint         i, m = 2^56, X(any)
   
   private:
    as integer          j
End Type

constructor.tMelgo:  redim x(n)
    for i as ulong = 0 to n
      x(i) = timer * 10
    next
    sched_new
end constructor

sub tMelgo.sched_new
    for i as ulong = 0 to n
      a = ( a+b+i )mod(n + 1)
      b = (b+c)mod(n+1)
      c = (c+a)mod(n+1)
      x(i) = ( x(i) + a*b*c*d + i )mod m
    next:  i = 0:  j = -1
End Sub

operator tMelgo.cast as ulong
    j=(j+1)mod 3
    select case as const j
    case 0:  x(a)=(x(b)+x(c)) mod m
      a=(a+b+i)mod(n+1)
      return x(a)+x(b)
    case 1
      b=(b+c)mod(n+1)
      return x(b)+x(c)
    case 2
      c=(c+a)mod(n+1):  i += 1
      return x(c)+x(a)
    End Select
End Operator

operator tMelgo.cast as string
    return str(culng(this))
End Operator
Last edited by dafhi on Sep 04, 2018 15:00, edited 9 times in total.
deltarho[1859]
Posts: 2696
Joined: Jan 02, 2017 0:34
Location: UK

Re: asm .members

Postby deltarho[1859] » Sep 01, 2018 11:22

jj2007 wrote:I tested PractRand a year ago, and was not very satisfied: It crashes with an illegal read exception...

I never could get v0.93 to work and have been using v0.92 (2014-11-18) for some years. I have just spotted v0.94 (2018-08-04) and downloaded it.

I use the command line 'My_RNG | RNG_test stdin32' for 32 bit output RNGs.

Here is My_RNG.bas for testing PCG32II.bas

Code: Select all

#Include "PCG32II.bas"
 
Dim Shared S As String * 1048576
Dim As Ulong Ptr SPtr, BasePtr
Dim As Long j
Dim pcg as pcg32
 
pcg.MyRandomize
 
SPtr = Cptr(Ulong Ptr, StrPtr( S ))
BasePtr = SPtr
 
Do
  For j = 1 to 262144
    *SPtr = pcg.rand ' 32 bit output
    SPtr += 1
  Next
  Print S;
  SPtr = BasePtr
Loop
 
Sleep

Typical output, I copied the console at 32GB and will let it run further

Code: Select all

F:\PR64>My_RNG | RNG_test stdin32
RNG_test using PractRand version 0.94
RNG = RNG_stdin32, seed = unknown
test set = core, folding = standard (32 bit)
 
rng=RNG_stdin32, seed=unknown
length= 256 megabytes (2^28 bytes), time= 2.7 seconds
  no anomalies in 165 test result(s)
 
rng=RNG_stdin32, seed=unknown
length= 512 megabytes (2^29 bytes), time= 5.8 seconds
  Test Name                         Raw       Processed     Evaluation
  DC6-9x1Bytes-1                    R=  -4.7  p =1-2.5e-3   unusual
  ...and 177 test result(s) without anomalies
 
rng=RNG_stdin32, seed=unknown
length= 1 gigabyte (2^30 bytes), time= 11.7 seconds
  no anomalies in 192 test result(s)
 
rng=RNG_stdin32, seed=unknown
length= 2 gigabytes (2^31 bytes), time= 22.7 seconds
  no anomalies in 204 test result(s)
 
rng=RNG_stdin32, seed=unknown
length= 4 gigabytes (2^32 bytes), time= 43.9 seconds
  no anomalies in 216 test result(s)
 
rng=RNG_stdin32, seed=unknown
length= 8 gigabytes (2^33 bytes), time= 87.7 seconds
  no anomalies in 229 test result(s)
 
rng=RNG_stdin32, seed=unknown
length= 16 gigabytes (2^34 bytes), time= 173 seconds
  no anomalies in 240 test result(s)
 
rng=RNG_stdin32, seed=unknown
length= 32 gigabytes (2^35 bytes), time= 340 seconds
  Test Name                         Raw       Processed     Evaluation
  DC6-9x1Bytes-1                    R=  -4.5  p =1-3.5e-3   unusual
  ...and 250 test result(s) without anomalies

Return to “General”

Who is online

Users browsing this forum: No registered users and 7 guests