Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to generate random number between 44 to 55 ?

Status
Not open for further replies.

venkatec

Newbie level 6
Joined
Aug 16, 2006
Messages
14
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
Hyderabad
Activity points
1,378
how to generate random numbers between 1 and 55

Hi Dear Frnds,

How to generate random number between 44 to 55 in verilog or VHDL?
 

random number between 55 to 77 in verilog

using LFSR(Linear feedback Shift Register) u can generate pseudo random numbers out of them use 3 bits to 44 so that u will random numbers from 44 to 52, now add two different bits from LFSR register to this u will get random numbers between 44 and 55.
 

uniform distribution in verilog

Unfortunately, the distribution isn't uniform then.
 

uniform distribution verilog command

I think if you use a LFSR that have a very long period should give uniform distribution but as you are saying than it may not. However than what other way is to get uniform distribution?
 

By adding two random numbers, you already change the distribution. You can use a mapping of the 1...2^n-1 LFSR number range to 44..55 by a table or a mod 12 operation. In case of a sufficient LFSR bitwidth, the distribution unsymmetry is only small. Dropping the unwanted numbers is another option.
 

Sorry as I am unable to get how you are generating random numbers, can you plz more elaborate it...
 

LFSR random number generators have an uniform distribution over their respective number range of 1...2^n-1, where n ist the number of stages.

To get an uniform distribution over the range 44..55 respectvively 0..11, you need a mapping that keeps the uiniformity.

I was discussing different mapping options: e.g. look up table or mod 12 operation. Your original suggestion creates also a mapping, but it violates uniformity and has a range of 0..10 instead of required 0..11.
 

Thanks for your responses,

How to genrate random no between any range(Ex:Take some rane 55 to 71) using $random command in verilog.
 

Hi Frnd,

I tryed to use the syntax you have given but its printing different values
which are in not range
code follows here
-----------
module test();
reg a;
reg b;
reg c;
wire out;
reg[7] range;

always
repeat(24)
begin
#100
a = 1'b1;
b = 1'b1;


#100
a = 1'b0;
b = 1'b1;

end


always@(a or b)
begin
repeat(24)
begin
range = 55 + $random % 16;
end
$monitor(" ‰d ",range);
end

endmodule


output follows here


?d 66
# ?d 47
# ?d 58
# ?d 54
# ?d 67
# ?d 67
# ?d 48
# ?d 46
# ?d 57
# ?d 59
# ?d 64
# ?d 49
# ?d 63
# ?d 50
# ?d 69
# ?d 69
# ?d 42
# ?d 41
# ?d 62
# ?d 55
# ?d 55
# ?d 44
# ?d 51
# ?d 47
# ?d 41
# ?d 44
# ?d 42

Could you give me correct solution?

Thanks,
venkat k

Added after 1 hours 6 minutes:

Hi Frnd,

I got the solution for this

we have to use the random command like this.
we should use { } brackets like below.

range = 55 + {$random} % 16;

This gives values between 55 to 77


Thanks,
venkat k

Added after 5 minutes:

The above one gives value between 55 to 71
not 55 to 77...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top