Like the subject says, I know this subject has been touched like 5000000 times.. I searched the forums for help but it did no good as none of the subjects I was looking for touched on the particular length of number I want to generate. I want to generate a number that is around 25 characters long. Does anyone know how this could be done? Examples would be great because I have tried doing it as well. thanks in advance...

RIF
Posted on 2002-10-24 18:24:30 by resistance_is_futile
come on guys I really need help on this...
Posted on 2002-10-24 20:08:56 by resistance_is_futile
Just get 25 single random numbers and put them into a Buffer and call wsprintf :)

There'a a nice random algo on Iczelion's site. I use a modified version of it as the first number is always the same on the original version :( So I injected a GetTickCount as random Seed before the first call and I wrote some inside the proc as it destroys almost every register.

I think it was this one : Pseudo Random Number Generator from S3
Posted on 2002-10-24 20:25:44 by JimmyClif
yea i have that example and i got it to work to print out only numbers 1-6 but i cant get it to make like a big number..I guess I would have to do it like 25 times but then the numbers would only be 1-6. Anyway i could do it through 1-9? I tried changing it but it starts giving out weird characters (letters and stuff). Anyway this could be changed. Here is the source where it needs to be changed but I cant get it to print randomly 1-9. can anyone else?


Rand proto :DWORD ;Generates a number on [0,Max-1]
Randomize proto :DWORD ;Changes the seed for Rand

.const
N equ 624
M equ 397
MATRIX_A equ 9908b0dfh
TEMPERING_MASK_B equ 9d2c5680h
TEMPERING_MASK_C equ 0efc60000h
UM equ 80000000h
LM equ 7fffffffh

.data
mti dd (N+1)
MC dd 69069

.data?
mt dd 2496 dup(?)

.code
Randomize proc Seed:DWORD
lea edi,mt
mov eax,Seed
mov [edi],eax
mov mti,1
@R: add edi,4
mul MC
mov [edi],eax
inc mti
cmp mti,N
jnz @R
ret
Randomize endp

Rand proc Max:DWORD
LOCAL Counter:DWORD
lea edi,mt
.IF mti>=N
.IF mti==N+1
INVOKE Randomize,4357
.ENDIF
mov Counter,0
mov esi,edi
@S: mov eax,[esi]
and eax,UM
mov ebx,[esi+4]
and ebx,LM
or eax,ebx
mov ecx,eax
shr eax,1
mov edx,esi
add edx,(M*4)
mov ebx,[edx]
xor eax,ebx
and ecx,1
.IF ecx
xor eax,MATRIX_A
.ENDIF
mov [esi],eax
add esi,4
inc Counter
cmp Counter,(N-M)
jnz @S

@T: mov eax,[esi]
and eax,UM
mov ebx,[esi+4]
and ebx,LM
or eax,ebx
mov ecx,eax
shr eax,1
mov edx,esi
add edx,((M-N)*4)
mov ebx,[edx]
xor eax,ebx
and ecx,1
.IF ecx
xor eax,MATRIX_A
.ENDIF
mov [esi],eax
add esi,4
inc Counter
cmp Counter,(N-1)
jnz @T

mov edx,edi
add edx,(M-1)*4
mov ebx,[edx]
xor eax,ebx
and ecx,1
.IF ecx
xor eax,MATRIX_A
.ENDIF
mov [esi],eax
mov mti,0
.ENDIF
mov esi,edi
mov eax,mti
inc mti
shl eax,2
add esi,eax
mov eax,[esi]
mov ebx,eax
shr eax,11
xor ebx,eax
mov eax,ebx
shl eax,7
and eax,TEMPERING_MASK_B
xor ebx,eax
mov eax,ebx
shl eax,15
and eax,TEMPERING_MASK_C
xor ebx,eax
mov eax,ebx
shr eax,18
xor eax,ebx
xor edx,edx
div Max
mov eax,edx
ret
Rand endp


amd the actual code




.ELSEIF ax==1001 ;Rand(6)=0 to 5
INVOKE Rand,6 ;Die=rand(6)+1=1 to 6
add al,49
mov Num,al
INVOKE MessageBox,hWnd,addr Num,addr Caption2,40000h
.ENDIF
Posted on 2002-10-24 21:00:55 by resistance_is_futile
Did you try calling it like this?

invoke Rand, 9 > should return 0->8 and all you need is an inc eax to get 1->9


I changed this line


.IF mti==N+1
INVOKE Randomize,4357
.ENDIF

into this.


.IF mti==N+1
invoke GetTickCount
INVOKE Randomize,eax
.ENDIF

as said before that it always returned the same number first.
Posted on 2002-10-24 21:10:53 by JimmyClif
ok i tried


invoke Rand, 9

and changed what u said in the include file and after that I put


inc al
mov Num,al

as inc eax does work but it does nothing when the number is in al. This like Isaid before gave out a whole bunch of weird characters.
Posted on 2002-10-24 22:19:57 by resistance_is_futile
Alright, I can't help you too much as I have no means to try but as far as I remember the Rand algo did it's wonders for me.

Try this:



Buffer db 128 dup (?)

push ebx
xor ebx,ebx
A1:
invoke Rand,9
add al,50
mov byte ptr [Buffer+ebx], al
inc ebx
cmp ebx, 25
jnz A1
invoke MessageBox, NULL, ADDR Buffer, NULL, MB_OK
Posted on 2002-10-25 07:30:11 by JimmyClif
did u try compiling that? I did and it didnt work...Your not the only one who has to help. More people could I guess they just feel they shouldnt or something...
Posted on 2002-10-25 12:43:34 by resistance_is_futile
A little bit of common sense is expected :(

Look at this screenshot (I just modified some code inside Rand.asm)
Posted on 2002-10-25 18:08:02 by JimmyClif
I know...I have common sense but not for this stuff. I have been programming for a while but when it comes to all that lea eax,eax stuff i am clueless thats why i was asking about api..I guess if Im going to program in assembly im going to have to learn it sooner or later. Well thanks again.
Posted on 2002-10-25 18:41:11 by resistance_is_futile
np :alright:
Posted on 2002-10-25 18:46:11 by JimmyClif
...when it comes to all that lea eax,eax stuff i am clueless...


Doesn't anyone watch code with a debugger?

Does anyone use a debugger?
Posted on 2002-10-25 23:42:48 by eet_1024
I have softice but I cant get it to work with my xp machine so I just dont use it.. anyone know how to get it to work I would be glad with the help :D
Posted on 2002-10-27 16:17:53 by resistance_is_futile

I have softice but I cant get it to work with my xp machine so I just dont use it.. anyone know how to get it to work I would be glad with the help :D
The FAQ here will direct you to some help for that. ;)
I use Ollydbg to step through my code...
Posted on 2002-10-27 16:43:19 by bitRAKE
If I wanted to make a random 25 charecter number I would probably use a regular random number procedure (probably KISS), and divide the result by 477218588 so it is a number 0-9, and then add 48 so it is ASCII, and do that 25 times. Then null terminate and thats it.
Posted on 2002-10-28 17:32:57 by Stan
This is NaNs random number generator which i have found is quite nice. Use it to generate a number from 0 to 9 as many times as you like and make a string out of them and convert back to number.

code:

mov eax, RAND32(9) ; generate a number between 0 and 9
_______________________________________

SWAP MACRO M1:REQ, M2:REQ
xor M1, M2
xor M2, M1
xor M1, M2
ENDM

RAND32 MACRO base:REQ
; Random number generator based on the Real time clock
; and the Park, Miller random number algorithm
;
; Coded by NaN for WIN32ASM
; May 5, 2001
; rev 2.


push ecx
push edx

ifndef __RAND_BY_NAN__
__RAND_BY_NAN__ equ 1


db 0fh,31h
shr eax, 2
add eax, 1

mov NaNRand, eax
endif
mov eax, NaNRand
mov edx,0
mov ecx, 127773;q
div ecx ; eax == floor( seed / q)
; edx == remainder
SWAP eax, edx
push edx
mov ecx, 16807
mul ecx ; eax = mul of remainder * a
pop edx ; edx == floor of seed/q

SWAP eax, edx
push edx
mov ecx, 2836
mul ecx
pop edx ; edx == mull of rem * a
; eax == mull of seed/q * r

sub edx, eax
mov eax, edx
mov NaNRand, eax ; save next seed
mov ecx, base
mov edx, 0
div ecx
mov eax, edx
pop edx
pop ecx
EXITM <eax>
ENDM

Don't know for sure if it can generate a 0 (zero) because i never used it for that purpose.

:alright:
Posted on 2002-10-28 17:59:49 by IwasTitan