home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 6431 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

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