Recent

Author Topic: Direct Access to PRNG_STATE  (Read 1432 times)

MathMan

  • Sr. Member
  • ****
  • Posts: 325
Direct Access to PRNG_STATE
« on: June 08, 2020, 11:51:47 am »
Hi all,

I would like to know if there is a way to directly access the prng-state of the mersenne-twister (current PRNG used in FPC iiuc)?

Background:

1 - I would like to retrieve the lowest 128-256 bit, after a call to Random(), consider them as a fractional and then do an upward multiplication with a 128 bit integer to generate a range restricted 128 bit integer random.

2 - currently I have to do this by first generating a 128 bit random integer (via 4 individual calls to Random( $100000000 )) and then do a downward modulo reduction to the required range.

Solution 2 has some disadvantages, as it requires substantially more time and, via the downward modulo, I am loosing the uniform distribution qualities of the Mersenne Twister (if my math serves me right).

Regards,
MathMan

PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: Direct Access to PRNG_STATE
« Reply #1 on: June 08, 2020, 12:00:25 pm »
I would like to know if there is a way to directly access the prng-state of the mersenne-twister (current PRNG used in FPC iiuc)?

No, there is not. In addition to that the PRNG used is an implementation detail, so this may change depending on the version or platform.

If you need specific properties, then use your own PRNG.

440bx

  • Hero Member
  • *****
  • Posts: 4065
Re: Direct Access to PRNG_STATE
« Reply #2 on: June 08, 2020, 12:13:19 pm »
@MathMan,

If you need specific properties, then use your own PRNG.

If you decide to follow that advice, check out ACORN if you haven't already.

HTH.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

MathMan

  • Sr. Member
  • ****
  • Posts: 325
Re: Direct Access to PRNG_STATE
« Reply #3 on: June 08, 2020, 12:41:28 pm »
I would like to know if there is a way to directly access the prng-state of the mersenne-twister (current PRNG used in FPC iiuc)?

No, there is not. In addition to that the PRNG used is an implementation detail, so this may change depending on the version or platform.

If you need specific properties, then use your own PRNG.

Understood, will use my own PRNG then.

MathMan

  • Sr. Member
  • ****
  • Posts: 325
Re: Direct Access to PRNG_STATE
« Reply #4 on: June 08, 2020, 12:42:28 pm »
@MathMan,

If you need specific properties, then use your own PRNG.

If you decide to follow that advice, check out ACORN if you haven't already.

HTH.

Thanks for the hint - I'll take a look at it.

MathMan

  • Sr. Member
  • ****
  • Posts: 325
Re: Direct Access to PRNG_STATE
« Reply #5 on: June 09, 2020, 07:53:42 am »
@MathMan,

If you need specific properties, then use your own PRNG.

If you decide to follow that advice, check out ACORN if you haven't already.

HTH.

I looked at it, but it does provide too little state for my requirements. I finally opted for an xoshiro-variant, which is very fast and passes e.g. TestU01.

Kind regards,
MathMan

440bx

  • Hero Member
  • *****
  • Posts: 4065
Re: Direct Access to PRNG_STATE
« Reply #6 on: June 09, 2020, 08:18:54 am »
I looked at it, but it does provide too little state for my requirements. I finally opted for an xoshiro-variant, which is very fast and passes e.g. TestU01.

Kind regards,
MathMan
I'm pleased you found an algorithm that meets your needs. 
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Direct Access to PRNG_STATE
« Reply #7 on: June 09, 2020, 01:43:08 pm »
@MathMan,

If you need specific properties, then use your own PRNG.
If you decide to follow that advice, check out ACORN if you haven't already.
HTH.

I looked at it, but it does provide too little state for my requirements. I finally opted for an xoshiro-variant, which is very fast and passes e.g. TestU01.

Kind regards,
MathMan
Is this xoshiro-variant solution you used open source?

MathMan

  • Sr. Member
  • ****
  • Posts: 325
Re: Direct Access to PRNG_STATE
« Reply #8 on: June 09, 2020, 04:26:48 pm »
Is this xoshiro-variant solution you used open source?

Looking at http://vigna.di.unimi.it/xorshift/ I got the impression, that the algorithm and the C-implementation are FOSS. I'll have to translate to FPC of course, but this is very little effort it seems.

 

TinyPortal © 2005-2018