FPC has built-in pseudo-random number generator. There are (in System unit) three overloaded random functions exposed to public (as we can see here).However, If I want to get pseudo-random Integer (32-bit sequence), I don't know how. The version of Random which returns integer takes a positive argument and returns a value between zero and this argument -- so the most I can get is 31-bit (if I pass MaxInt to the function).Looking in sources, we can see that all these three functions internaly call function genrand_MT19937, which is not exposed to public (it is under implementation section of System unit).If I understand well, this genrand_MT19937 function returns pseudo-random Longint. If I had access to this function, I could get pseudo-random 32-bit number. For 64-bit number I could useCode: Pascal [Select](qword(cardinal(genrand_MT19937)) or ((qword(cardinal(genrand_MT19937)) shl 32)Shouldn't we have access to this function? Seems to me that all three Random functions that we have exposed in system unit cut something from result of this original function.Before I ask for this in bug tracker, I would like to discuss it here.
Zoran,The whole of the 32 bits are used. To obtain a signed random it is sufficient to assign to a signed type That's the case with FPC's internal mt19937 and with my IM.So part of your concern is already solved...
all random functions which we can use cut something from result.
Quote from: Zoran on April 05, 2017, 11:55:25 amall random functions which we can use cut something from result.That is normal. And according to specs. Signed is always 31 bits,unsigned is 32 bits. The intermediate (IM) gives the full 32 bit value for unsigned. That's logical since all operations are bitwise.
function Random(U: UInt32): UInt32; (and likewise for UInt64) might be welcome addition to RTL?Bart
Quote from: Zoran on April 05, 2017, 10:09:46 pmExactly!File a feature request in the fpc bugtracker, and if possible, attach a patch.Bart