home *** CD-ROM | disk | FTP | other *** search
- Path: cs.ruu.nl!usenet
- From: wsldanke@cs.ruu.nl (Wessel Dankers)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: random number in assembly
- Date: 27 Mar 96 23:22:57 +0100
- Organization: Dept of Computer Science, Utrecht University, The Netherlands
- Message-ID: <1203.6660T1402T2876@cs.ruu.nl>
- References: <Pine.NEB.3.91.960327200012.12939A-100000@dirty.cute.fi>
- NNTP-Posting-Host: anx1p9.cc.ruu.nl
- X-Newsreader: THOR 2.22 (Amiga TCP/IP)
-
- Kristian Slavov <kslavov@dirty.cute.fi> wrote:
- > Hi!
- > Could someone tell me how to get a VERY WELL randomized number?
- > I've tried all kinds of methods but they are not enough random :(
- > To make the problem a little bit harder I need a routine that can be used
- > in loops so that the numbers wouldn't be for ex. 4,8,12,16,20 or
- > 2,3,4,5,6,7. Hope you understood that :)
-
- This is the one I always use (in C sorry):
-
- It takes bits 0 and and 1 of the previous number and XOR's them.
- Then (after shifting that 31 to the left) it OR's it with the original number
- (after shifting that right 1). There are also probably too many brackets in
- it.
-
- unsigned int seed = 0x47E25FC4; // feel free to init this to whatever you like
-
- unsigned int rand(void)
- { return seed = (seed>>1)|((((seed & 1)^((seed & 2)>>1)))<<31);
- }
-
-
- --
- Wessel Dankers _\\|//_ <wsldanke@cs.ruu.nl>
- ///|\\\
- ----------------------------oOO--(_)---OOo----------------------------
- `Never imagine yourself not to be otherwise than what it might appear
- to others that what you were or might have been was not otherwise than
- what you had been would have appeared to them to be otherwise.'
-
-