samedi 17 juin 2017

Creating a procedure that generates a random string

So I want to generate a random string, in which the length of the string is defined by the user (n).

Using Randomize and RandomRange from the Irvine32 library, I want to generate random numbers within the range displayed on the ASCII table for uppercase letters (65-90).

After that, I want to use a procedure like StringPrint to convert and output into string chars.

This is the code I have so far...

INCLUDE c:\Irvine\Irvine32.inc


ExitProcess proto,dwExitCode:dword

.data       
prompt byte "Please enter a number between 1 and 50: ",0dh,0ah,0
prompt2 byte "The generated string is... ",0dh,0ah,0
space byte " ",0
n dword ?
rangeup dword ?
.code
main proc
mov ebx, 65
mov eax, 90
mov rangeup, eax

mov edx, offset prompt
call WriteString
call ReadInt
mov n, eax

call Crlf
mov edx, offset prompt2
call WriteString

call Randomize
mov ecx, n
L1:
pushad                                          ;//save all 32bit registers
call GenerateNumbers
call WriteInt
mov edx, offset space
call WriteString
popad                                           ;//restore all 32bit registers
loop L1


call Crlf
call Crlf
invoke ExitProcess, 0
main endp

GenerateNumbers proc
add rangeup, ebx
call randomrange
sub rangeup, ebx
ret
GenerateNumbers endp

end main




Aucun commentaire:

Enregistrer un commentaire