Are there any tutorials on how to write a random number generator? All ive ever found is code for one, which i can never get to work. But id like to write my own so i can learn to write it better for each situation.
I think there is none. The general rule of random number is to have the highest and lowest number(range - depends on you, the programmer) eg. 1 - 10. Most programmers use the bios time, in conjunction with the range limit, which i think the result isn't true random number. Take a look at www.random.org they have an engine that calculates random number based on the atmosperic pressure(i think?). Generating true random numbers on your pc can be based on mouse movement, time... Other sources for generating numbers can be temperature, radioactive radiation...
I hope i'm not off topic.
Pssst. What if the atmospheric pressure at 10:00am is X after 5 minutes it's X...It's still isn't random...But hey!!! I'm not here to start a war.
www.agner.org - has a random number generator in asm.
I hope i'm not off topic.
Pssst. What if the atmospheric pressure at 10:00am is X after 5 minutes it's X...It's still isn't random...But hey!!! I'm not here to start a war.
www.agner.org - has a random number generator in asm.
Hi.
NaN wrote, and shared in the forum, an excellent asm random number generator. Either search the forum or his site...
http://www.angelfire.com/scifi/win32asm/index.html
and you should be able to find it. If not, re-post and I'll link to a copy.
Btw, thanks, NaN.
NaN wrote, and shared in the forum, an excellent asm random number generator. Either search the forum or his site...
http://www.angelfire.com/scifi/win32asm/index.html
and you should be able to find it. If not, re-post and I'll link to a copy.
Btw, thanks, NaN.
Thanx for the praises, im glad you like...
But in all fairness i seem to remember hearing the WizKid TechnoMagic (sp??) made a faster and cleaner random generator.. I havent varified this, but i seem to remember Zakiel talking about this a week or 2 ago...
Mine was me putting the duldrums of Statistics to good use, it serves my purpose quite well, but im sure there is better somewhere... (as i put no extra effort into optomizations).
Anyways thanx again!
NaN
But in all fairness i seem to remember hearing the WizKid TechnoMagic (sp??) made a faster and cleaner random generator.. I havent varified this, but i seem to remember Zakiel talking about this a week or 2 ago...
Mine was me putting the duldrums of Statistics to good use, it serves my purpose quite well, but im sure there is better somewhere... (as i put no extra effort into optomizations).
Anyways thanx again!
NaN
; High quality Random Algo from a "G. Adam Stanislav":
; http://www.geocities.com/SiliconValley/Heights/7394/
;
; 2 Functions are available in this example, to be called as:
;
; > call 'RND.Random' ; Returns a random dWord in eax
; > call 'RND.RangeRandom' 125 849 ; Returns a random dWord between 125 and 849,
; ; (including given limits).
Proc Random::
Uses ecx edx
mov eax D?Rand | movzx edx B?Rand+4
shrd eax edx 1 | mov D?Rand eax
adc dh 0 | shr dl 1
mov cl dl | shr cl 2 | and cl 1
xor dh cl | shl dh 6 | or dl dh
mov B?Rand+4 dl
EndP
____________________________________________________
Proc RangeRandom::
Arguments @Min, @Max
Uses ecx, edx
mov eax D?Rand | movzx edx B?Rand+4
shrd eax edx 1 | mov D?Rand eax
adc dh 0 | shr dl 1
mov cl dl | shr cl 2 | and cl 1
xor dh cl | shl dh 6 | or dl dh
mov B?Rand+4 dl
mov ecx D@Max | sub ecx D@Min | inc ecx | mul ecx
mov eax edx | add eax D@Min
EndP
____________________________________________________
InitRandomize:
call 'KERNEL32.GetTickCount'
mov B?Rand al | shl D?Rand 8
mov B?Rand ah | shl D?Rand 8
mov B?Rand al | shl D?Rand 8
mov B?Rand al | xor D?Rand 06227_8134
ret
betov.
; http://www.geocities.com/SiliconValley/Heights/7394/
;
; 2 Functions are available in this example, to be called as:
;
; > call 'RND.Random' ; Returns a random dWord in eax
; > call 'RND.RangeRandom' 125 849 ; Returns a random dWord between 125 and 849,
; ; (including given limits).
Proc Random::
Uses ecx edx
mov eax D?Rand | movzx edx B?Rand+4
shrd eax edx 1 | mov D?Rand eax
adc dh 0 | shr dl 1
mov cl dl | shr cl 2 | and cl 1
xor dh cl | shl dh 6 | or dl dh
mov B?Rand+4 dl
EndP
____________________________________________________
Proc RangeRandom::
Arguments @Min, @Max
Uses ecx, edx
mov eax D?Rand | movzx edx B?Rand+4
shrd eax edx 1 | mov D?Rand eax
adc dh 0 | shr dl 1
mov cl dl | shr cl 2 | and cl 1
xor dh cl | shl dh 6 | or dl dh
mov B?Rand+4 dl
mov ecx D@Max | sub ecx D@Min | inc ecx | mul ecx
mov eax edx | add eax D@Min
EndP
____________________________________________________
InitRandomize:
call 'KERNEL32.GetTickCount'
mov B?Rand al | shl D?Rand 8
mov B?Rand ah | shl D?Rand 8
mov B?Rand al | shl D?Rand 8
mov B?Rand al | xor D?Rand 06227_8134
ret
betov.
you can also make for example a string with the current date, followed by a dword with the result of a gettickcount, and apply a md5 hash on it =) this might however be a bit long :p
Roy,
Off topic here, but i seem to remember you did a bunch of work with Hash tables and hashing functions a while ago??
If im correct, do you think you would have sample code you could send me such i can build a Hash Table object for the new MASM object set im working on..?? Of course full credit will go your way, but i think this would be a good asset to the current set.
If so, Email me @: jaymeson@hotmail.com
Thanx..
NaN
Off topic here, but i seem to remember you did a bunch of work with Hash tables and hashing functions a while ago??
If im correct, do you think you would have sample code you could send me such i can build a Hash Table object for the new MASM object set im working on..?? Of course full credit will go your way, but i think this would be a good asset to the current set.
If so, Email me @: jaymeson@hotmail.com
Thanx..
NaN