Re: A92: random number


[Prev][Next][Index][Thread]

Re: A92: random number




Thank you very much Benoît. I cannot translate the french quotes too. I
don't even understand what "un générateur de séquence congruentielle
linéaire" is, but I understand the algorithm. It is very helpful, thanx
again. As for the code in x86 asm, I wanted it in 68k asm, and I agree that
x86 asm sucks. I someone can give me the 68k asm code, you're welcome.
Thank you everybody who answer my question.

MP <philhuck@club-internet.fr>

-----Message d'origine-----
De : Famille SCHERRER <p.c.Scherrer@wanadoo.fr>
À : 'a92' <assembly-92@lists.ticalc.org>
Date : mercredi 9 septembre 1998 20:14
Objet : Re: A92: random number



hy,

I studied a little bit the way to generate random numbers.
(for polymorph & genetic viruses ;-)  )

First it is impossible to generate real random numbers.
Even John  Von Neumann said (in french, sorry, I don't know
how to translate it) : "Quiconque supposerait l'emploi de méthodes
algorithmiques pour la production de chiffres aléatoires serait
dans l'erreur" (if someone can translate it...)

So all random number generators are pseudo random numbers
generators.
And it is very very hard to make good random number generators.

A good way to generate random numbers is to use (in french again,
sorry) "un générateur de séquence congruentielle linéaire). I didn't
known what is was before but in fact it is quite simple.  Here is how
to do :

Xn+1 = (a * Xn + c) mod m

where a, c, and m are positives. (it is quite the same way as
explain Arno Kizina)

If the choice of a, c, and m is good, the generator will be
quite good. But if you make a bad choice, it will be very bad.
Sorry, I don't know how to make a good choice.


Here is the code of such a generator in x86 asm :
(the x86 assembly is a real shit. The 68k is 10000 x better !)

M DD 134217729
A DD 44739244
C DD 134217727
Rand_Seed DD 0

;--------------
;set Rand_Seed up with a random number to seed the
;pseudo random generator.
;--------------
RANDOM_SEED:
push si ds dx cx bx ax
call RS1 ;it is just for the virus for
RS1: pop bx ;making it totally relocatable
sub bx, offset RS1 ;using bx
xor ax,ax
mov ds,ax
mov si,46ch ;it is the timer if i don't make a mistake
lodsd
xor edx,edx
mov ecx,M
div ecx
mov cs:[bx][Rand_Seed],edx
pop ax bx cx dx ds si
ret

;---------
;return pseudo-random number in ax
;--------
Get_Random:
push bx cx dx
call GR1
GR1: pop bx
sub bx,offset GR1
mov eax,[bx][Rand_Seed]
mov ecx,[bx][A]
mul ecx ;Xn * A
add eax,[bx][C] ;Xn * A   + C
adc edx,0
mov ecx,[bx][M] ;mod
div ecx ;M
mov eax,edx
mov [bx][Rand_Seed],eax
pop dx cx bx
ret


If you want more informations you can also read
The Art of Computer Programming of Donald E.Knuth
(Seminumerical algorithms, vol2, p1-170, Addison Wesley,
1981)

Good luck !!!
Benoit SCHERRER
E-Mail : mailto:p.c.scherrer@wanadoo.fr
Web :    http://perso.wanadoo.fr/scherrer