flat assembler
Message board for the users of flat assembler.
Index
> Windows > Random number generation via GetSystemTime() |
Author |
|
revolution 17 Feb 2011, 08:56
Well the system timer is a terrible source for random numbers. Here is a better source:
Code: proc rand uses ebx,store,length local context:DWORD invoke CryptAcquireContext,addr context,NULL,NULL,PROV_RSA_FULL,CRYPT_VERIFYCONTEXT test eax,eax jz .done invoke CryptGenRandom,[context],[length],[store] test eax,eax setz bl invoke CryptReleaseContext,[context],0 test eax,eax setz al or al,bl movzx eax,al dec eax .done: ret endp |
|||
17 Feb 2011, 08:56 |
|
Overflowz 17 Feb 2011, 09:20
revolution
Thanks for reply! isn't there any other way to make random number only with using kernel32/user32 libraries ? Cause I'm learning libraries step by step so I'm now only on kernel32, user32 and some from shell32 libs.. Thanks. |
|||
17 Feb 2011, 09:20 |
|
revolution 17 Feb 2011, 09:33
There are lots and lots of ways to make pseudo random numbers without even using the system APIs. But you already complained about the quality of your simple method, so most of those easy ways won't suit you. Generating good quality randomness is not easy to do and for a beginner the process may appear to be overwhelming in its complexity. The crypto APIs solve this difficult problem and present an easy to use interface to extract good quality randomness.
BTW: The ADVAPI32 is part of the core OS libraries and is always available, just like KERNEL32 and USER32, so don't worry about it not being there. BTW2: Things like the C rand() function is also a terrible random number generator. It is just a simple LCG algorithm with awful "randomness" properties. |
|||
17 Feb 2011, 09:33 |
|
Overflowz 17 Feb 2011, 10:21
revolution
Thank you, I'll learn that too. p.s Dev-C++ algorithm sucks really ^^ when calling only random, first comes 41 every time hehe. Thanks for useful post! |
|||
17 Feb 2011, 10:21 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.