A strong PRNG

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

Re: A strong PRNG

Post by deltarho[1859] »

neil wrote:all you ever do is make fun of and criticise people.
That is a gross exaggeration.
I know now that I will never ask you for help;
Thank you.
neil
Posts: 591
Joined: Mar 17, 2022 23:26

Re: A strong PRNG

Post by neil »

@dodicat
Here's something I found by John Cook. Uniform sampling from an ellipse. There is a simple way to randomly sample points from an ellipse, but it is not uniform. The Quasi Monte Carlo / Monte Carlo python example worked.
https://www.johndcook.com/blog/tag/rng/
dafhi
Posts: 1641
Joined: Jun 04, 2005 9:51

Re: A strong PRNG

Post by dafhi »

neat. reminds me of relsoft's re-param spline
neil
Posts: 591
Joined: Mar 17, 2022 23:26

Re: A strong PRNG

Post by neil »

@dafhi
I did some research on the quantum world and its interesting.
https://www.space.com/quantum-physics-t ... hould-know
dafhi
Posts: 1641
Joined: Jun 04, 2005 9:51

Re: A strong PRNG

Post by dafhi »

"meh." a lot of that is taught in chemistry. having said that, i'm no astro-physicist

cool.
neil
Posts: 591
Joined: Mar 17, 2022 23:26

Re: A strong PRNG

Post by neil »

The author Colin Stuart did a great job of explaining it where you could understand it. I am still researching it. I won't post anything more about it because the post's would be endless.
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: A strong PRNG

Post by deltarho[1859] »

neil wrote:I did some research on the quantum world and its interesting.
I am still researching it.
See what I mean, folks.

I have just finished a book 'Black Holes: The Key to Understanding The Universe' by Bran Cox and Jeff Forshaw both professors of particle physics.

The latter part of the book looks at the relationship between quantum entanglement, Hawking radiation and holograms.

When neil has finished his research, perhaps he can explain the relationship because, currently, I am struggling with it and will go back to the book for a re-read of the latter part.

:)
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: A strong PRNG

Post by deltarho[1859] »

Actually, it may be a good idea to depart this thread before the admin has a word with me.

Departed. :)
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: A strong PRNG

Post by coderJeff »

deltarho[1859] wrote: Apr 02, 2023 16:16 Actually, it may be a good idea to depart this thread before the admin has a word with me.

Departed. :)
I missed my chance? :)

My opinion without doubt is that you, deltarho[1859], are the expert on pseudo random number generation. Your level of technical detail offered about the subject is impressive and daunting. I admit, I am the uneducated in this regard. I sympathize with neil. Once upon a time having received criticism for fb's implementation of PRNG's and attempting to improve our offering, I gave up and put it aside. And even now it annoys me that I have an uncommitted branch of PRNG improvement lingering in my development tree for fear that I have not done my homework thoroughly.
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: A strong PRNG

Post by deltarho[1859] »

codeJeff wrote:I missed my chance? :)
Yes, I was pushing it.
I sympathize with neil.
I don't. There have been some excellent PRNGs put forward since I joined FreeBASIC six years ago. Neil presented a PRNG first mentioned by John Cook fifteen years ago. Cook should have 'pulled ' that Code Project years ago because it is not a strong PRNG. The opening post looks at (r1 mod 256) as a small prng number 0 - 255. If r1 is random, there is no guarantee that (r1 mod 256) will be.

The opening post is then fundamentally flawed.

Later on because 'A strong PRNG' was beginning to look flaky, PractRand's integrity was questioned a couple of times and even Windows was questioned. Linux was starting to smell of roses because it found no fault. Phrases like 'trying to run before we can walk', 'a little knowledge is dangerous' and so on come to mind.

I first got into PRNGs with some code by John Gleason at the PowerBASIC forum in 2004. John and I collaborated quite a bit on PRNGs and developed a PRNG called RND2 to replace PB's RND. That was based upon Marsaglia's Multiply-with-Carry. That was not difficult as PB's RND is exceptionally poor. I started it and John came in with a lot of asm; which PowerBASIC needs. I don't know why, but John has not posted for five years. So, I have been at it for nearly 20 years. Maybe I am not as bright as I think I am because I am still learning. Of course, it could be that random numbers as a subject is much deeper than I thought it was when I started this journey.

I shouldn't get 'rattled' but I cannot help it when someone comes into the subject talking as if they know what they are talking about when in fact what they know can be put on the back of a postage stamp. To be fair to neil when Professor O'Neill presented her PCG family of PRNG's she'd never heard of PractRand either. She does now and swears by it. Professor Vigna also uses PractRand. His early 128-bit and 256-bit period PRNGs were flawed. His, with David Blackman, latest 128-bit and 256-bit period PRNGs, xoroshiro128** and xoshiro256**, are superb.

Anyway, thanks for your recognition, coderJeff. Being recognized by a master compiler writer is some recognition. I am uneducated in that regard by a long way. :wink:

Departed continues. :)
dafhi
Posts: 1641
Joined: Jun 04, 2005 9:51

Re: A strong PRNG

Post by dafhi »

don't need mersenne. if deltarho had a non-asm version, that might easily ported

RoMu would be an excellent starting point (author has several versions)

this is mine and has nearly flat distribution. It's good for monte-carlo

Code: Select all

a *= a
a xor= b
b += 1
hhr
Posts: 208
Joined: Nov 29, 2019 10:41

Re: A strong PRNG

Post by hhr »

But for simple tasks you can also use the fb-rnd's. Works with algorithm 3 and 5. Tested with PractRand.

Code: Select all

randomize ,3 '[3|5]

function rnd32 as ulong
   return rnd * 4294967295
end function

function rnd64 as ulongint
   union rndunion
      as ulongint n64
      as ulong n32(1)
   end union
   dim as rndunion number
   number.n32(0) = rnd * 4294967295
   number.n32(1) = rnd * 4294967295
   return number.n64
end function

do
   print rnd32, rnd64
loop until getkey = 27 ' Esc
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: A strong PRNG

Post by deltarho[1859] »

I said departed. OK, I will behave myself. :)

@hhr

Code: Select all

Randomize ,3 '[3|5]

Function rnd32 As ULong
   Return Rnd*2^32
End Function

Function rnd64 As ULongInt
   Return (Cast( ULongInt, Rnd*2^32 ) Shl 32) Or Cast( ULongInt, Rnd*2^32 )
End Function

Do
   Print rnd32, rnd64
Loop Until GetKey = 27 ' Esc
We can use 2^32 because Rnd < 1.
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: A strong PRNG

Post by deltarho[1859] »

@dafhi

I liked RomuTrio but was not sold on the non-guaranteed period. I am not good at taking people's word for things and did not test to prove his claim that a shortish period was unlikely, especially when we would not know if that was what we may be experiencing. Besides, I am not that persuaded on speed nowadays. Romu was found to be not that fast in 64-bit mode. Once we get past a certain speed, it becomes academic. For me, the most important metric is randomness.

I am glad to see that someone recognizes that Monte Carlo work needs a flat distribution and not necessarily good randomness – the flatter, the better.
hhr
Posts: 208
Joined: Nov 29, 2019 10:41

Re: A strong PRNG

Post by hhr »

Thank you deltarho[1859]. I value your opinion a lot because I think you are an expert. But I think you should be lenient against neil. You are the teacher.

What is 'flat distribution'? Can I have an example?
Post Reply