Continue to Site

# [SOLVED]Is random numbers after mod still random?

Status
Not open for further replies.

#### naught

##### Member level 3
Im considering the Linear Feedback Shift Register to generate the uniform distributed numbers.
I tried using short FFs to generate sequences. but it seems to me not random because the FFs is short, and sequence repeated itself in a short and fixed cycle.

So I try the longer FFs, say 63 bits LFSR.
But I have a question here. Since the integers between 0 to 3 is all what I want, and thus I would map all the numbers confined to the range between 0 to 3, by mod function.
say if number 42 is generated, 42 mod 4 => 2, then I get 2.
in the end, just a sequence of 0,1,2,3 is desirable.

Does this change the randomness(even though its pseudo random)? and is the sequence still uniformly distributed?

Personally I feel it is, because the mod function is, at least it seems to me, sort of linear(it`s not)

Last edited:

In a maximum length LFSR sequence, each number occurs exactly once. Thus the distribution of the result sequence can be easily counted.

I THINK that if your register length is an integer multiple of 4, then you will still have a uniform distribution. But I don't think there is ANY advantage to creating a longer LFSR. Why would you do this?

the longer you make it, it may appear more random if you only look at the bottom 2 bits, but you will still get each value 0-3 the same number of times over 2^n samples (where n is the width of the LFSR)

naught

### naught

Points: 2
What's the problem? You have your whatever length LFSR. You pick the LFSR length such that the repetition lenght is "sufficiently large" for your particular design. The lfsr spits out a single bit per clock. This generates a loooooong string of bits. And you chop this up in pieces of 2-bits in your case, but you could for example do 8-bits if you wanted random bytes. And if an infinite length bit string is random, then so is the chopped up 2-bits per number for your 0-3 range.

naught

### naught

Points: 2
I changed my mind, instead of using mod function, it might be better to chop off 2-bits of the LFSR.~~~

FvM, barry, TrickyDicky, mrflibble, thank you guys all!!
you guys are amazing!!!

Status
Not open for further replies.