UCLONG / NetEmulation

Software Simulation and Hardware Synthesis of Electrical and Optical Interconnection Networks
GNU General Public License v3.0
10 stars 6 forks source link

Random number distribution #13

Closed BorisDosen closed 10 years ago

BorisDosen commented 10 years ago

I've been looking into distribution of the pseudo random number generated by this code

logic [7:0] l+r8; logic [(log2AndRoundUp(`PORTS))-1:0] l_temp; //'PORTS=10, making l_temp 4bit

l_r8 <= (2^8)-(`SEED * (port_no+1));
l_r8 <= {l_r8[6:0], (l_r8[0] ^ l_r8[4] ^ l_r8[5] ^ l_r8[7])};
l_temp <= l_r8; //taking the last 4 bits of l_r8

For some reason number 0000 and 1111 are not generated as often as all the other numbers. Strange, as the distribution of l_r8 looks fine! Any ideas?

Here is the graph: distribution

DannyNicholls commented 10 years ago

nice graph!

I don't have time to look right now, but if you put that question on this forum

http://www.edaboard.com/forum30.html

an answer shall arrive swiftly. Let me know if you get a solution, just incase I start trying to work it out :+1:

DannyNicholls commented 10 years ago

Just a thought though, if l_r8 is fine, I imagine that truncating a random number may not necessarily result in a random number. Especially with the 0000 and 1111 limit.

pmwatts commented 10 years ago

Something a bit strange here! In a peusdo-random binary sequence produced by a shift register, zero should never appear - think about how the shift register works to convince yourself that this is true. However, the maximum value should appear as often as any other. I notice that if you add the zeros to the 15s you would get the expected result - is this just a bug!

Phil


From: Danny Nicholls notifications@github.com Sent: 21 February 2014 20:21 To: DannyNicholls/NetEmulation Subject: Re: [NetEmulation] Random number distribution (#13)

Just a thought though, if l_r8 is fine, I imagine that truncating a random number may not necessarily result in a random number. Especially with the 0000 and 1111 limit.

Reply to this email directly or view it on GitHubhttps://github.com/DannyNicholls/NetEmulation/issues/13#issuecomment-35769550.

p-andreades commented 10 years ago

Boris, have you tried taking the first 4 most significant bits instead of the last 4 ones? I'm not sure if this will make any difference but maybe taking the 4 least significant bits of an 8-bit vector is what causing 0000 to appear.

DannyNicholls commented 10 years ago

There is a LFSR for random numbers in the altera cookbook, could you just use that?

http://www.altera.com/literature/manual/stx_cookbook.pdf

They also propose a random number generation from a ring oscillator which looks interesting.

I started googling to see how these work and found an in depth explanation here, and decided to go to bed instead lol.

http://www.ovro.caltech.edu/~dwh/correlator/pdf/lfsr_tutorial.pdf