News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

nrandom broken, or am i doing something wrong?

Started by white scorpion, May 27, 2006, 06:49:17 PM

Previous topic - Next topic

white scorpion


.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

Ossa

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
Website (very old): ossa.the-wot.co.uk

white scorpion

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!

Ossa

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
Website (very old): ossa.the-wot.co.uk

white scorpion

Well, it doesn't really matter how it works, just as long as you know how to use it  :toothy