FreeBASIC's PRNG #2

General FreeBASIC programming questions.
Post Reply
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: FreeBASIC's PRNG #2

Post by deltarho[1859] »

dafhi wrote:nothing is unpredictable. :P
Heisenberg's uncertainty principle.

The thermal noise of a CPU is reckoned to be unpredictable and why Intel use it for RdRand.
dafhi
Posts: 1640
Joined: Jun 04, 2005 9:51

Re: FreeBASIC's PRNG #2

Post by dafhi »

but it's not algorithmic
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: FreeBASIC's PRNG #2

Post by deltarho[1859] »

@dafhi

You wrote 'nothing' and not 'nothing algorithmic'. I try not to second guess.
dafhi
Posts: 1640
Joined: Jun 04, 2005 9:51

Re: FreeBASIC's PRNG #2

Post by dafhi »

you're right. i was assuming the three of us understood that the conversation was about algorithmic computation
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: FreeBASIC's PRNG #2

Post by deltarho[1859] »

dafhi wrote: i was assuming the three of us understood that the conversation was about algorithmic computation
Ha, ha. A reasonable assumption but not when people like me or MrSwiss are reading posts and, as you know, MrSwiss does not take prisoners. <laugh>
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FreeBASIC's PRNG #2

Post by dodicat »

Hi dafhi.
Do you use PractRand for testing?
It seems a bit contrary.(Irish version contrairie)
I have taken a whole rotation off my previous 64 bit randomizer (to try and speed it up)
I was expecting a complete duffer, but PractRand tells me all is well to 128Gb.

Code: Select all

 Microsoft Windows [Version 10.0.17134.285]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\User\Desktop\bin\random\PractRand_0.94\PractRand_094\bin\msvc12_64bit>pipefile | rng_test stdin32 -multithreade
d
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= 3.1 seconds
  no anomalies in 165 test result(s)

rng=RNG_stdin32, seed=unknown
length= 512 megabytes (2^29 bytes), time= 6.4 seconds
  no anomalies in 178 test result(s)

rng=RNG_stdin32, seed=unknown
length= 1 gigabyte (2^30 bytes), time= 12.5 seconds
  no anomalies in 192 test result(s)

rng=RNG_stdin32, seed=unknown
length= 2 gigabytes (2^31 bytes), time= 23.9 seconds
  no anomalies in 204 test result(s)

rng=RNG_stdin32, seed=unknown
length= 4 gigabytes (2^32 bytes), time= 47.7 seconds
  no anomalies in 216 test result(s)

rng=RNG_stdin32, seed=unknown
length= 8 gigabytes (2^33 bytes), time= 108 seconds
  no anomalies in 229 test result(s)

rng=RNG_stdin32, seed=unknown
length= 16 gigabytes (2^34 bytes), time= 236 seconds
  no anomalies in 240 test result(s)

rng=RNG_stdin32, seed=unknown
length= 32 gigabytes (2^35 bytes), time= 503 seconds
  no anomalies in 251 test result(s)

rng=RNG_stdin32, seed=unknown
length= 64 gigabytes (2^36 bytes), time= 1057 seconds
  no anomalies in 263 test result(s)

rng=RNG_stdin32, seed=unknown
length= 128 gigabytes (2^37 bytes), time= 2144 seconds
  no anomalies in 273 test result(s)

  
And my new pipefile

Code: Select all


'rng_test stdin32 -multithreaded
'pipefile.exe


Type random2
	Dim As Ulongint a,b,c,d,e
    Declare Function Valu() As Ulongint
    Declare Function Valf() As Double
    Declare Sub seed(As Ulongint)
End Type

Function random2.valu() As Ulongint
	e = a-((b Shl 39) Or (b Shr 25))
	a = b xor ((c Shl 11) Or (c Shr 53))
    b = c + d
	c = d + e
	d = e + a
	Return d
End Function

Function random2.valf() As Double
	e = a-((b Shl 39) Or (b Shr 25))
	a = b xor ((c Shl 11) Or (c Shr 53))
    b = c + d
	c = d + e
	d = e + a
	Return d/18446744073709551615
End Function

Sub random2.seed(z As Ulongint)
    This=Type(4058668781,z,z,z)
    For i As Ulongint=1 To 20
        Valu
    Next
End Sub


Dim As random2 p
p.seed(100)

Dim Shared S As String * 1048576
Dim As Ulong Ptr SPtr, BasePtr
Dim As Long j

SPtr = Cptr(Ulong Ptr, Strptr( S ))
BasePtr = SPtr

Do
    For j = 1 To 262144
        *SPtr = p.valu
        SPtr += 1
    Next
    Print S;
    SPtr = BasePtr
Loop
  
I also get good values from ENT with this.
dafhi
Posts: 1640
Joined: Jun 04, 2005 9:51

Re: FreeBASIC's PRNG #2

Post by dafhi »

deltarho[1859] wrote:
dafhi wrote: i was assuming the three of us understood that the conversation was about algorithmic computation
Ha, ha. A reasonable assumption but not when people like me or MrSwiss are reading posts and, as you know, MrSwiss does not take prisoners. <laugh>
bro, you're all right :-)
dafhi
Posts: 1640
Joined: Jun 04, 2005 9:51

Re: FreeBASIC's PRNG #2

Post by dafhi »

dodicat wrote:Hi dafhi.
Do you use PractRand for testing?
i haven't been able to get it to work.

I use the approach viewtopic.php?f=3&t=26996&start=180#p252031
but i just see a blank console
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: FreeBASIC's PRNG #2

Post by jj2007 »

deltarho[1859] wrote:An unpredictable sequence would be non-reversible
But if you encrypt a file, you want the sequence used to be reversible, otherwise it's just garbage, right? Some years ago I coded this Simple Encryption Algorithm, using a PRNG that passes ENT but not PractRand. All it does is xor'ing the sequence with the file to be encrypted. The resulting file is random. Of course, if you knew for certain one single dword of that file, you could reconstruct the sequence. But if you don't, how could you "attack" the encryption?
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FreeBASIC's PRNG #2

Post by dodicat »

Dafhi :Compile my file to pipefile.exe

pop a shell.exe into folder
PractRand_0.94\PractRand_094\bin\msvc12_64bit
and pop in pipefile.exe also.

from the shell.exe use pipefile.exe | rng_test stdin32 -multithreaded

For shell.exe
compile
shell "cmd"

Once you get it working put your own 64 bit randomizer into pipefile.bas.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: FreeBASIC's PRNG #2

Post by deltarho[1859] »

jj2007 wrote:But if you encrypt a file, you want the sequence used to be reversible, otherwise it's just garbage, right?
Correct.

dafhi was talking about toying with non-reversibility. I suggested toying with unpredictability and non-reversibility follows.

jj, you are going off on a tangent talking about encryption.
dafhi
Posts: 1640
Joined: Jun 04, 2005 9:51

Re: FreeBASIC's PRNG #2

Post by dafhi »

I ran pipefile in fbc and i get a bunch of text with text and beeps where each beep causes a fraction of a second pause
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: FreeBASIC's PRNG #2

Post by paul doe »

dafhi wrote:i haven't been able to get it to work.

I use the approach viewtopic.php?f=3&t=26996&start=180#p252031
but i just see a blank console
Bear in mind that the code it's assuming that you're executing it from where 'RNG_test.exe' is located. If you wand to run PractRand from another folder, simply modify the cmd string to account for the full path:

Code: Select all

dim as string cmd = practRandFullPath & "RNG_test stdin32 -multithreaded"
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FreeBASIC's PRNG #2

Post by dodicat »

Just compile pipefile.bas.
Let PractRand run pipefile.exe as described (the command shown ... pipefile.exe | rng_test stdin32 -multithreaded) , there will no no text or beeps.
It takes a few seconds to warm up, so be patient.
dafhi
Posts: 1640
Joined: Jun 04, 2005 9:51

Re: FreeBASIC's PRNG #2

Post by dafhi »

jj2007 wrote: if you encrypt a file, you want the sequence used to be reversible, otherwise it's just garbage, right? ?
I was talking about the ability to write a sequence backwards. From a developer's point of view, this would be a great platform from which to create a difficult-to-attack algorithm.
Post Reply