The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: smallboy on November 09, 2005, 05:28:49 PM

Title: Howto use nrandom function
Post by: smallboy on November 09, 2005, 05:28:49 PM
Hello
I'm a beginer. I dont know to use exact nrandom function in masm32.lib. I did do as following:

386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
include \masm32\m32lib\masm32.inc
includelib \masm32\m32lib\masm32.lib

.data
MsgBoxCaption  db "Iczelion Tutorial No.00",0
zz db '%4X',0
buffer dd 128 dup (0)




.code



start:

INVOKE GetTickCount
invoke nrandom,eax

invoke wsprintf,addr buffer,offset zz, eax
invoke MessageBox, NULL, addr buffer, addr MsgBoxCaption, MB_OK
invoke ExitProcess, NULL

end start


Exact?????

please help me.
Title: Re: Howto use nrandom function
Post by: dsouza123 on November 10, 2005, 02:18:33 AM
Other than small syntax items,
.386 instead of 386
and some .data items db instead of dd

.data
zz db "%6X",0             ; took 6 chars + 0 in all tests
buffer db 128 dup (0)

.code
start:

by not invoking nseed, eax before invoking nrandom,eax

  invoke GetTickCount
  invoke nrandom,eax

becomes essentially

  invoke GetTickCount
  mov ecx, eax
  mov edx, 0
  mov eax, 1335380034    ; 4F984842h the result of 12345678 as seed
  div ecx
  mov eax,edx

should probably do

  invoke GetTickCount
  invoke nseed,eax
  invoke nrandom,eax
Title: Re: Howto use nrandom function
Post by: hutch-- on November 10, 2005, 02:38:59 AM
hmmmmm,

It may help to read the help file where the procedure is documented.

Quote
nrandom

nrandom proc base:DWORD

Description
A Park Miller random algorithm written by Jaymeson Trudgen (NaN) and optimised by Rickey Bowers Jr. (bitRAKE).

Parameter
1.   base  Zero based range for random output.

Return Value
Random number within range set in "base" in EAX.

Comments
The seed for the random algorithm is set as a variable of GLOBAL scope in a seperate procedure atached to the library module. The variable is nrandom_seed and this variable should be set with a DWORD size number prior to the use of this algorithm.
Title: Re: Howto use nrandom function
Post by: MichaelW on November 10, 2005, 02:45:31 PM
Also, if you are generating a sequence of numbers, reseeding the generator with the tick count before each call will destroy the randomness of the generated sequence.

Title: Re: Howto use nrandom function
Post by: P1 on November 10, 2005, 03:14:07 PM
smallboy,

Welcome to MASMforum!      :U

Read around the different areas and get a feel for the place.     :dazzled:

Read the help files and tutorials of MASM32.   It's best, if you download the most recent MASM32 package and install it. 

'Search' & Google are your friends for programming.  Then ask your questions.     

Regards,  P1  :8)