home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!van-bc!rsoft!agate!ames!haven.umd.edu!darwin.sura.net!gatech!purdue!news.cs.indiana.edu!umn.edu!epx.cis.umn.edu!rogers
- From: rogers@epx.cis.umn.edu
- Newsgroups: sci.math
- Subject: Psuedo Random sequences Help needed
- Summary: Binary psuedo random sequence, which bits or XORed in?
- Message-ID: <1992Aug29.230020.12972@news2.cis.umn.edu>
- Date: 29 Aug 92 23:00:20 GMT
- Sender: news@news2.cis.umn.edu (Usenet News Administration)
- Organization: University of Minnesota
- Lines: 43
-
-
- I am need a random sequence for a graphics effect, and I can't
- remember which bits to exclusive or together. About ten years ago
- I used data in a book to generate 24 bit sequences, but right now I need
- a 12 bit sequence. This is how it works:
-
- xxxxxxxxxxxx
- -->010101011001 <- a 12 bit binary number that will be shifted right
- | | |
- | | | <- two bits to be excluse ored together (and the result
- | <-bit \ / inverted and shifted back in)
- | shifted []
- | back in |
- \ /
- ------------
-
- The sequence will lock up if all ones are in the register, but otherwise
- should give every number between zero and 4095 (inclusive) in an apparently
- random order. This is just what I need for what I am doing because I
- need every number once to clear every location on the screen in a random
- order.
-
- The problem is I cannot remember which bits to XOR (or XNOR) together
- and I think I have tried every combination. (of two bits) I know that
- some of the larger (bit length) sequences needed four bits to XNOR together.
-
- Does this sound familer to anyone? Does anyone know what book I could
- find it in?
-
- In C, the algorithm looks like this: (R=num, P= 2^p, Q= 2^q , p and q are bits)
- (bits 0 and 3 were used in the example above,
- which would give P=2^0=1 and Q=2^3=8 )
-
- if (((R&P)&!(R&Q))||(!(R&P)&(R&Q))) /* R bit p XORed with R bit q */
- R = R >>1; /* R = R/2 */
- else
- R = (R+4096)>>1; /* R gets a one shifted in */
-
-
- Thanks in advance,
- Brynn
-
- rogers@epx.cis.umn.edu (612) 536-6444
-