flat assembler
Message board for the users of flat assembler.

Index > Main > Random Number Generator in FASM

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Angler



Joined: 28 Jul 2006
Posts: 13
Angler
Hi!
I'm working on a program that needs a random numbers.
I've read loads of articles devoted to "Random Number Generator".
They are too difficult to understand:
Firstly, there are a lot about Theory Of Chances, and other mathematic stuff.(I'm not strong in that)
Secondly, and maybe lastly most of them are written in english, (english isn't my native language, that's why maybe they're dif. to understand).(my ntv lng is russian)
But somehow, i managed to understand a little.

Maybe someone has suggestions, how to write such kind of functions.
Or give me a link.

Thank you very much! Sorry for my english, it's not very good.
Post 03 Aug 2006, 09:53
View user's profile Send private message Reply with quote
HyperVista



Joined: 18 Apr 2005
Posts: 691
Location: Virginia, USA
HyperVista
Привет Angler!
Here's a link you may find helpful
http://www.random.org/

For me, it's not advised to write your own encryption because it is so difficult to get it correct and not provide weak encryption by mistake. We have a name for self written encryption ... "encraption". It's best to use well established libraries for encryption work.

Успехов!
Post 03 Aug 2006, 10:01
View user's profile Send private message Visit poster's website Reply with quote
Angler



Joined: 28 Jul 2006
Posts: 13
Angler
Большое спасибо! Ща загляну! Than you very much!
Post 03 Aug 2006, 10:06
View user's profile Send private message Reply with quote
HyperVista



Joined: 18 Apr 2005
Posts: 691
Location: Virginia, USA
HyperVista
Пожалуйста

Here are some ASM examples of RNGs and support files. Source is :http://www.agner.org/random/


Description:
Download
Filename: randoma.zip
Filesize: 69.68 KB
Downloaded: 714 Time(s)

Post 03 Aug 2006, 10:22
View user's profile Send private message Visit poster's website Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM
I happen to have a translation of a 'xorshift' algorithm from C. Here it is:


Description:
Download
Filename: xorshift.asm
Filesize: 492 Bytes
Downloaded: 758 Time(s)


_________________
This calls for... Ultra CRUNCHY Man!
Ta da!! *crunch*
Post 03 Aug 2006, 12:24
View user's profile Send private message Reply with quote
Angler



Joined: 28 Jul 2006
Posts: 13
Angler
HyperVista, how to oficcially ask in english "Довольны ли вы своей зарплатой?"(1) & "А мы и не сомневались, что вы так ответите."(2)?
Я эксперементирую, и хочу просто создать прикольную программу, которая спрашивает (1), на форме две кнопки (Да, Нет). Когда юзер наводит на "Нет", эта кнопка "убегает". Пользователю ничего не остаётся, как ответить "Да". Ну и тут сообщение (2). Классный прикол! Правда старый, но мне нравится!

Довольно странный вопрос кого-то перевести что это значит на другом языке, но всё же? В любом случае спасибо!!
Post 05 Aug 2006, 15:25
View user's profile Send private message Reply with quote
Angler



Joined: 28 Jul 2006
Posts: 13
Angler
I've been studying these RNG last 2 days. But it's too hard to write own function, so it's better to use established one.
Post 05 Aug 2006, 15:32
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
Try RtlRandom and RtlRandomEx (WinXP or better) from ntdll.dll.
This functions do not pass any statistical tests (diehard, nist), but they may be used for the task you described, I think.
Post 05 Aug 2006, 16:46
View user's profile Send private message Reply with quote
Angler



Joined: 28 Jul 2006
Posts: 13
Angler
Thank you zhak! What i've described is a small useless program. It can be used only as example.

I find it difficult to write my own RNG function, so this small prog uses library from Agner Fog. Sorry for english, Here that useless program!

By the way, how to write this code in FASM and what does it mean?
Code:
        MOV     [M0][ECX*4], EAX
    

(I met it when i was translating MASM code into FASM)


Description:
Download
Filename: Bank.zip
Filesize: 5.38 KB
Downloaded: 559 Time(s)

Post 06 Aug 2006, 05:13
View user's profile Send private message Reply with quote
HyperVista



Joined: 18 Apr 2005
Posts: 691
Location: Virginia, USA
HyperVista
Привет Angler!

The english translation of your questions is a little difficult, but I'll give it a try:

Are you satisfied with your salary? (Yes or No)
We knew you would answer yes

I know a young person here who is Russian and speaks very good english (he's the brother of my daughter's friend). He is very interested in programming and can help you translate your program prompts to english. You can e-mail him at markov792004@yahoo.com. He'd be happy to assist you.

Успехов!
Post 06 Aug 2006, 16:35
View user's profile Send private message Visit poster's website Reply with quote
Sasha



Joined: 17 Nov 2011
Posts: 93
Sasha
I wrote, seems, the simplest implementation of decent linear congruential generator. According to http://en.wikipedia.org/wiki/Linear_congruential_generator the a=69069 ,c=1 and m=2^32 were used in old versions of glibc

Code:
  Rand:                         ;Linear congruential generator
        mov     eax,[X0]        ;X0
        mov     edx,69069       ;a=69069
        mul     edx
        inc     eax             ;c=1
        mov     [X0],eax
        ret                               
    

Let's leave c=1 and m=2^32. I want to find other a's that will give a good sequense.
If you will use this code in your project, please let me know, if it works good.
And don't use it in cryptography!
Post 21 Jun 2013, 13:30
View user's profile Send private message Reply with quote
Sasha



Joined: 17 Nov 2011
Posts: 93
Sasha
There are some variations of parameters on this page
http://www.gnu.org/software/gsl/manual/html_node/Other-random-number-generators.html

As we can see, some of them don't require even the incremention so they are truly multiplicative.
Code:
Rand:                         ;Linear congruential generator 
        mov     eax,[X0]        ;X0 
        mov     edx,1664525       ;a=1664525, 1812433253, 1566083941
        mul     edx 
        mov     [X0],eax 
        ret                               
    
Post 23 Jun 2013, 09:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17474
Location: In your JS exploiting you and your system
revolution
I only ever use LCGs where low speed and low quality are not a problem. A trivial computer game would be a good usage case for an LCG.
Post 23 Jun 2013, 09:53
View user's profile Send private message Visit poster's website Reply with quote
Sasha



Joined: 17 Nov 2011
Posts: 93
Sasha
Yes, only one multiplication, but so slow!!!
Now I'm working on mersenne twister and xorshift algorithms.
Post 23 Jun 2013, 12:18
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1413
Location: Toronto, Canada
AsmGuru62
I have posted the Mersenne Twister here:
http://board.flatassembler.net/topic.php?t=13741
Post 23 Jun 2013, 13:05
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17474
Location: In your JS exploiting you and your system
revolution
Sasha wrote:
Yes, only one multiplication, but so slow!!!
I don't mean the implementation is slow. I mean that for a slow consumer of random numbers this might suffice for some purposes. If you have a rapid consumer then the short repetition period can be harmful. Most Monte-Carlo simulations would suffer a great deal by using such a simple generator.
Post 23 Jun 2013, 13:48
View user's profile Send private message Visit poster's website Reply with quote
Sasha



Joined: 17 Nov 2011
Posts: 93
Sasha
If it would be possible to make extremely fast implementation of LCG, the period could be extended by choosing larger numbers.
Post 23 Jun 2013, 16:36
View user's profile Send private message Reply with quote
Sasha



Joined: 17 Nov 2011
Posts: 93
Sasha
AsmGuru62 wrote:
I have posted the Mersenne Twister here:
http://board.flatassembler.net/topic.php?t=13741

Thank you, I think it'll be very usefull. I'm trying to understand the algorithm.
Post 23 Jun 2013, 16:41
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1413
Location: Toronto, Canada
AsmGuru62
Post 23 Jun 2013, 19:56
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17474
Location: In your JS exploiting you and your system
revolution
Sasha wrote:
If it would be possible to make extremely fast implementation of LCG, the period could be extended by choosing larger numbers.
Speed of generation is not the issue. Even if it could be generated instantly it is still a poor generator for many purposes. LCGs are low quality and this must be considered when deciding which class of generator to use for the needed purpose.
Post 24 Jun 2013, 00:16
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.