Post Reply 
Hp Algorithm to create random numbers
08-24-2024, 12:05 AM
Post: #12
RE: Hp Algorithm to create random numbers
(08-23-2024 01:42 PM)Albert Chan Wrote:  But when I try RDZ, above 4 cases all give random state 001
Only when seed get smaller, does this state pattern activated, why the gap?

1E-13 --> 001
1E-14 --> 001
1E-15 --> 001
1E-16 --> 001
1E-17 --> 991
1E-18 --> 981
1E-19 --> 971

There's more to RDX's algorithm than your table implies.

RDX separates the mantissa and exponent fields of the real number given as input, and then treats the mantissa as a 15-digit integer while combining the two into a seed. The exponent stays as a 3-digit number, but it may not be what you expect due to the special way negative exponents for reals are encoded in the Saturn architecture. Specifically, negative exponents are encoded as 1000-ABS(exponent), but RDX simply treats that result as a 3-digit positive integer.

The denormalization section of the code performs right-shifts on the mantissa based on the exponent value.

Note that there are 3 independent exit conditions in RDX's denormalization loop:
- the mantissa becomes 0 as a result of repeated right-shifts, OR
- (2*exponent) <= 998 (ie. a carry does NOT occur as a result of 2*exponent), OR
- (2*exponent) MOD 1000 is 0

So here's the critical values for some specific inputs that will hopefully show what's happening.

Input 1E-12
Initial mantissa: 100000000000000
Initial exponent:             988
Mantissa after denormalization: 000000000001000
Exponent after denormalization:             000
Exponent after shift-left:                  000
Exponent after increment:                   001
Seed:                           000000000001001

Input 1E-13
Initial mantissa: 100000000000000
Initial exponent:             987
Mantissa after denormalization: 000000000000100
Exponent after denormalization:             000
Exponent after shift-left:                  000
Exponent after increment:                   001
Seed:                           000000000000001

Input 1E-14
Initial mantissa: 100000000000000
Initial exponent:             986
Mantissa after denormalization: 000000000000010
Exponent after denormalization:             000
Exponent after shift-left:                  000
Exponent after increment:                   001
Seed:                           000000000000001

Input 1E-15
Initial mantissa: 100000000000000
Initial exponent:             985
Mantissa after denormalization: 000000000000001
Exponent after denormalization:             000
Exponent after shift-left:                  000
Exponent after increment:                   001
Seed:                           000000000000001

Input 1E-16
Initial mantissa: 100000000000000
Initial exponent:             984
Mantissa after denormalization: 000000000000000
Exponent after denormalization:             000
Exponent after shift-left:                  000
Exponent after increment:                   001
Seed:                           000000000000001

Input 1E-17
Initial mantissa: 100000000000000
Initial exponent:             983
Mantissa after denormalization: 000000000000000
Exponent after denormalization:             999
Exponent after shift-left:                  990
Exponent after increment:                   991
Seed:                           000000000000991

Input 123456.123456
Initial mantissa: 123456123456000
Initial exponent:             005
Mantissa after denormalization: 123456123456000
Exponent after denormalization:             006
Exponent after shift-left:                  060
Exponent after increment:                   061
Seed:                           123456123456061


Note how the last 3 digits of the mantissa get obliterated by the altered exponent in each example.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Hp Algorithm to create random numbers - DavidM - 08-24-2024 12:05 AM



User(s) browsing this thread: 1 Guest(s)