The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: white scorpion on May 27, 2006, 06:49:17 PM

Title: nrandom broken, or am i doing something wrong?
Post by: white scorpion on May 27, 2006, 06:49:17 PM

.686
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib

.data

.data?

nrandom_seed dd ?

.code

start:

    invoke GetTickCount
    mov nrandom_seed,eax
    @@:
    invoke nrandom,256
    jle @B

end start

This will generate the same array of numbers every time you start the program.
This is strange, since GetTickCount, which is used as the seed for the nrandom function does change every time you run the program.

Any ideas on this?

Tx
Title: Re: nrandom broken, or am i doing something wrong?
Post by: Ossa on May 27, 2006, 06:57:45 PM
You must set nrandom_seed using nseed:

    invoke nseed, eax

in place of

    mov nrandom_seed,eax

and then you can get rid of the variable "nrandom_seed".

I had to look at the code for nrandom (in masm32\m32lib\nrand.asm) to find that - it's not documented.

Ossa
Title: Re: nrandom broken, or am i doing something wrong?
Post by: white scorpion on May 27, 2006, 09:32:15 PM
Then a whole lot of people don't know that.
I've googled for "nrandom casemap" and got a lot of sourcecode, but all of them just moved eax to nrandom_seed  :toothy

Thanks for your help!
Title: Re: nrandom broken, or am i doing something wrong?
Post by: Ossa on May 27, 2006, 09:48:01 PM
It would work if the nrandom_seed variable was set to global scope (say, using EXTERNDEF) in the nrand.asm file and had an EXTERNDEF in the masm32.inc file... its just not been done. Instead, the undocumented nseed has been placed in there. Ah well, I posted about it in the MASM32 package section, hopefully hutch will change it for the next version.

Ossa
Title: Re: nrandom broken, or am i doing something wrong?
Post by: white scorpion on May 27, 2006, 09:53:00 PM
Well, it doesn't really matter how it works, just as long as you know how to use it  :toothy