Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » sci.math.* » sci.math.independent

Topic: RNGs: A Super KISS
Replies: 14   Last Post: Feb 26, 2013 10:53 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
adrian dogsbody

Posts: 110
Registered: 12/13/04
Re: A Super KISS
Posted: Nov 3, 2009 7:38 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


"geo" <gmarsaglia@gmail.com> ha scritto nel messaggio
news:a14dbdd8-cce7-4038-ad6b-a9f34b9c3cc4@f16g2000yqm.googlegroups.com...
> #include <stdio.h>
> static unsigned long Q
> [41790],indx=41790,carry=362436,xcng=1236789,xs=521288629;
>
> #define CNG ( xcng=69609*xcng+123 ) /*Congruential*/
> #define XS ( xs^=xs<<13, xs^=(unsigned)xs>>17, xs^=xs>>5 ) /
> *Xorshift*/
> #define SUPR ( indx<41790 ? Q[indx++] : refill() )
> #define KISS SUPR+CNG+XS
>
> int refill( )
> { int i; unsigned long long t;
> for(i=0;i<41790;i++) { t=7010176LL*Q[i]+carry; carry=(t>>32); Q[i]=~
> (t);}
> indx=1; return (Q[0]);
> }
>
> int main()
> {unsigned long i,x;
> for(i=0;i<41790;i++) Q[i]=CNG+XS;
> for(i=0;i<1000000000;i++) x=KISS;
> printf(" x=%d.\nDoes x=-872412446?\n",x);
> }


the asm version

; compile with
; nasmw -fobj rndasm.asm
; bcc32 -v rndasm.obj
section _DATA use32 public class=DATA
global _main
extern _printf

indx dd 41790
carry dd 362436
xcng dd 1236789
xs dd 521288629
IIIIIIxIIdIIn db " x=%d." , 13, 10, 0
IDoesIxII872412446IIn db "Does x=-872412446?" , 13, 10, 0
section _BSS use32 public class=BSS

vettoreQ resd 41792

section _TEXT use32 public class=CODE

align 4
initialize:
push esi
push edi
push ebp
mov ecx, 41790
mov esi, vettoreQ
mov edi, [xcng]
mov ebp, [xs]
.0: mov eax, 69609
mul edi
add eax, 123
xchg eax, edi
mov eax, ebp
shl eax, 13
xor ebp, eax
mov eax, ebp
shr eax, 17
xor ebp, eax
mov eax, ebp
shr eax, 5
xor ebp, eax
lea eax, [ebp+edi]
mov [esi], eax
add esi, 4
loop .0
mov [xcng], edi
mov [xs], ebp
pop ebp
pop edi
pop esi
ret

align 4
rnd:
push esi
push edi
mov ecx, [indx]
mov esi, vettoreQ
cmp ecx, 41790
jne .1
push esi
.0: mov eax, 7010176
mul dword[esi]
add eax, [carry]
adc edx, 0
mov [carry], edx
not eax
mov dword[esi], eax
add esi, 4
loop .0
pop esi
.1: mov edi, [esi+4*ecx]
inc ecx
mov [indx], ecx
mov eax, 69609
mov ecx, [xcng]
mul ecx
add eax, 123
mov [xcng], eax
add edi, eax
mov edx, [xs]
mov eax, edx
shl eax, 13
xor edx, eax
mov eax, edx
shr eax, 17
xor edx, eax
mov eax, edx
shr eax, 5
xor edx, eax
mov [xs], edx
add edi, edx
xchg edi, eax
pop edi
pop esi
ret

align 4
_main:
pushad
call initialize
mov esi, 0
.0: call rnd
inc esi
cmp esi, 1000000000
jb .0
mov edi, eax
push eax
push IIIIIIxIIdIIn
call _printf
add esp, 8
push IDoesIxII872412446IIn
call _printf
add esp, 4
popad
xor eax, eax
ret







Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.