Hi
Does any one know what is the bottom and top range of the random number generator in masm32/m32lib folder called nrand.asm?
For example in C++ the random number generator I think, the range is from 0 to 10 or something like that.
Thanks
For the nrandom procedure (in the file nrand.asm), you specify the range in the base parameter. The range of the returned numbers will be 0 to base - 1. So for example if you specified a base of 0FFh, the returned numbers would be in the range 0 to 0FEh. The maximum range would occur when you specified 0FFFFFFFFh in the base parameter. For the CRT rand function, the range is fixed at 0 to 7FFFh. You can determine the range by test, but for large ranges finding the true minimum and maximum values will probably take a long time.
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.data
min dd 0ffffffffh
max dd 0
.code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
xor ebx, ebx
.WHILE ebx < 1000000
invoke nrandom, 0ffh
inc ebx
.IF eax < min
mov min, eax
.ENDIF
.IF eax > max
mov max, eax
.ENDIF
.ENDW
print uhex$(min),9
print uhex$(max),13,10
mov min, 0ffffffffh
mov max, 0
xor ebx, ebx
.WHILE ebx < 1000000
invoke crt_rand
inc ebx
.IF eax < min
mov min, eax
.ENDIF
.IF eax > max
mov max, eax
.ENDIF
.ENDW
print uhex$(min),9
print uhex$(max),13,10,13,10
inkey "Press any key to exit..."
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
00000000 000000FE
00000000 00007FFF
Edit: I decided to test the full range for nrandom. Specifying a base value of 0FFFFFFFFh and increasing the loop count by a factor of 10 until I got the correct result:
00000000 FFFFFFFE
I ended up with a loop count of 1000000000 and a run time of perhaps 5 minutes.