Re: RNGs: A Super KISS
"user923005" <dcorbit@connx.com> ha scritto nel messaggio
news:1e22f0b0-01f3-4be4-8a5a-ce39bf86dc70@y28g2000prd.googlegroups.com...
On Nov 3, 12:23 pm, user923005 <dcor...@connx.com> wrote:
I copied and pasted from the wrong file. Here is the correct code
[snip]
class SuperKiss {
this is how i see it 2:
but it is not much portable (cpu x86, assembler nasm, c++ compiler borland)
then don't know if it is right...
what about this?
----x
Delta=23.000
i=-872412446
Does i=-872412446?
val u32 =3075790285
val double =0.647830
val u32 =4289339058
val i32 -10309 +309 =-6324
val d -10309 +309 =-6716.981099
---x
#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <stdlib.h>
#define u32 uint32_t
#define i32 int32_t
#define R return
#define P printf
#define F for
class SuperKiss{
public:
SuperKiss(u32, u32, u32); /* def costructor */
~SuperKiss(){ free(q); }
u32 SKRand(void); /* def function */
u32 urnd(void){R SKRand(); }
i32 irnd(void){R (i32) SKRand(); }
u32 urnd(u32 umin, u32 umax)
{if(umin>=umax) R 0;
R umin+SKRand()%(umax-umin+1);
}
i32 irnd(i32 imin, i32 imax)
{if(imin>=imax) R 0;
R imin+SKRand()%(imax-imin+1);
}
double drnd(void){R (double)SKRand()/0xFFFFFFFF;}
double drnd(double dmin, double dmax)
{if(dmin>=dmax) R 0.0;
R dmin + (dmax-dmin)*drnd();
}
u32* q;
u32 indx;
u32 carry;
u32 xcng;
u32 xs;
};
void initialize(SuperKiss* m);
SuperKiss::SuperKiss(u32 xcarry=362436, u32 xxcng=1236789, u32 xxs=521288629)
{u32 *v;
q=0; indx=0;
v=(u32*)malloc(41792* sizeof(u32));
if(v==0) R;
q=v; indx=41790; carry=xcarry; xcng=xxcng; xs=xxs;
initialize(this);
}
int main(void)
{double d;
time_t ti,tf;
SuperKiss sk, w;
i32 i;
u32 u, v;
if(sk.q==0||w.q==0)
{P("Too Few memory\n"); R 1;}
ti=time(0);
for(v=0; v<1000000000; ++v)
i=sk.irnd();
tf=time(0);
P("Delta=%.3f\n", (double)difftime(tf, ti));
P( " i=%d", (int) i);
P("\nDoes i=-872412446?\n");
P( "val u32 =%u \n", (unsigned) w.urnd());
P( "val double =%f \n", w.drnd());
P( "val u32 =%u \n", (unsigned) w.urnd());
P( "val i32 -10309 +309 =%i \n", (int) w.irnd(-10309, 309));
P( "val d -10309 +309 =%f \n", w.drnd(-10309, 309));
R 0;
}
-------------------
section _DATA use32 public class=DATA
global @initialize$qp9SuperKiss
global @SuperKiss@SKRand$qv
section _TEXT use32 public class=CODE
; 0q, 4indx, 8carry, 12xcng, 16xs
; 0k, 4j, 8i, 12ra, 16P
align 4
@initialize$qp9SuperKiss:
push esi
push edi
push ebp
mov ecx, 41790
mov edx, dword[esp+ 16]
mov esi, [edx]
mov edi, [edx+12]
mov ebp, [edx+16]
..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 edx, dword[esp+ 16]
mov [edx+12], edi
mov [edx+16], ebp
..1:
pop ebp
pop edi
pop esi
ret
align 4
ini:
mov esi, [edi]
..0: mov eax, 7010176
mul dword[esi]
add eax, [edi+8]
adc edx, 0
mov [edi+8], edx
not eax
mov dword[esi], eax
add esi, 4
loop .0
jmp short @SuperKiss@SKRand$qv.1
; 0j, 4i, 8ra, 12P
align 4
@SuperKiss@SKRand$qv:
push esi
push edi
mov edi, dword[esp+ 12]
mov ecx, [edi+4]
cmp ecx, 41790
je ini
..1: mov esi, [edi]
mov esi, [esi+4*ecx]
mov edx, [edi+16]
inc ecx
mov eax, edx
mov [edi+4], ecx
shl eax, 13
imul ecx, [edi+12], 69609
xor edx, eax
add ecx, 123
mov eax, edx
mov [edi+12], ecx
shr eax, 17
add esi, ecx
xor edx, eax
mov eax, edx
shr eax, 5
xor edx, eax
mov [edi+16], edx
lea eax, [esi+edx]
pop edi
pop esi
ret