SizeOfInteger.i = 8 * 4 ; 8 bits sur 4 octets
MaxInteger.i = Pow(2, SizeOfInteger)
;MaxInteger - 1 ; Bug : impossible de soustraire 1 ci-dessus si on met 8 octets à la place de 4 ;)
Debug "Plus grand nombre entier "
Debug MaxInteger
SizeOfFloat.i = 8 * 4
MaxFloat.i = Pow(2, SizeOfFloat)
Unit.d = 1.0 / MaxFloat
Debug "Plus petit nombre flottant "
Debug Unit
Debug "---"
For i = 0 To 100
FP.d = Unit * Random(MaxFloat)
UP.d = Random(MaxInteger)
DRnd.d = UP + FP
Debug DRnd
Next
; Pour un nombre
Define nombre.q
RandomData(@nombre, SizeOf(Quad))
Debug RSet(Hex(nombre, #PB_Quad),2*SizeOf(Quad), "0")
; Pour un tableau de nombres
#DIM_TABLEAU = 1000
Dim hazard.q(#DIM_TABLEAU)
RandomData(@hazard(0), (#DIM_TABLEAU+1)*SizeOf(Quad))
For i = 0 To #DIM_TABLEAU
Debug RSet(Hex(hazard(i), #PB_Quad),2*SizeOf(Quad), "0")
Next
Pour utiliser les valeurs aléatoires à des fins de chiffrement il faut mieux utiliser les fonctions CryptRandom() et CryptRandomData().