flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > pmrand

Author
Thread Post new topic Reply to topic
Ali.Z



Joined: 08 Jan 2018
Posts: 726
Ali.Z 20 Feb 2023, 14:44
Code:
A = 41A7h ; for better statistics use BC8Fh
M = 7FFFFFFFh
Q = M / A
R = M mod A

pmrand:
mov eax,[s]
mov ecx,Q
cdq ;fixed -2 issue
idiv ecx
imul eax,R
imul edx,A
xchg eax,edx
sub eax,edx
jns @f
add eax,M
@@:
mov [s],eax
ret ;eax ret value

;...

s dd 1 ;must be non-zero and not equ to M
    

_________________
Asm For Wise Humans


Last edited by Ali.Z on 21 Feb 2023, 05:45; edited 3 times in total
Post 20 Feb 2023, 14:44
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20423
Location: In your JS exploiting you and your system
revolution 21 Feb 2023, 03:58
A input value of -2 in [s] will generate zero. And the same for the (-2) shr 1 (= 0x7fffffff).

What do you mean by "better statistics"? Which statistics are you referring to?
Post 21 Feb 2023, 03:58
View user's profile Send private message Visit poster's website Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 726
Ali.Z 21 Feb 2023, 05:10
input value of 0x7FFFFFFF should not generate 0, this is silly mistake by me; I will fix it. (but there is no difference, even if I fix it, it would repeat 0x7FFFFFFF forever)
as for -2 generating 0, I really don't know; I will figure it out later.

better number distribution statistics (weighting).
note: it returns a value in open interval (0,M)

_________________
Asm For Wise Humans


Last edited by Ali.Z on 21 Feb 2023, 05:23; edited 2 times in total
Post 21 Feb 2023, 05:10
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4060
Location: vpcmpistri
bitRAKE 21 Feb 2023, 05:13
So, [s] range would be [1,0x7FFFFFFE], making 0x7FFFFFFF an invalid input?
Post 21 Feb 2023, 05:13
View user's profile Send private message Visit poster's website Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 726
Ali.Z 21 Feb 2023, 05:18
yes.

Ali.Z wrote:
I will fix it. (but there is no difference, even if I fix it, it would repeat 0x7FFFFFFF forever)


actually getting zero is good (if initial state is equ M), but if anyone don't want to get zero, then replace jns with jg. (in real world, it would never generate 0, the only way to get zero is by having initial state equ to M)

and fixed -2 issue.

_________________
Asm For Wise Humans
Post 21 Feb 2023, 05:18
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4060
Location: vpcmpistri
bitRAKE 21 Feb 2023, 15:37
The original Park-Miller article from 1988 can be found here:
http://www.cems.uwe.ac.uk/~irjohnso/coursenotes/ufeen8-15-m/p1192-parkmiller.pdf

... it says the A value was originally suggested in 1969.
Post 21 Feb 2023, 15:37
View user's profile Send private message Visit poster's website Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 726
Ali.Z 21 Feb 2023, 16:46

_________________
Asm For Wise Humans
Post 21 Feb 2023, 16:46
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4060
Location: vpcmpistri
bitRAKE 21 Feb 2023, 17:45
Nice, that links to the 1969 paper - which outlines the original testing method.
(Lehmer actually suggests 14^29 for the A, in 1954.)

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 21 Feb 2023, 17:45
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.