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?
 

saurabhmimani

Junior Member level 1
Joined
Jun 16, 2009
Messages
19
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,396
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.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,439
Helped
14,445
Reputation
29,154
Reaction score
13,245
Trophy points
1,393
Location
Bochum, Germany
Activity points
284,488
uniform distribution in verilog

Unfortunately, the distribution isn't uniform then.
 

saurabhmimani

Junior Member level 1
Joined
Jun 16, 2009
Messages
19
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,396
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?
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,439
Helped
14,445
Reputation
29,154
Reaction score
13,245
Trophy points
1,393
Location
Bochum, Germany
Activity points
284,488
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.
 

saurabhmimani

Junior Member level 1
Joined
Jun 16, 2009
Messages
19
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,396
Sorry as I am unable to get how you are generating random numbers, can you plz more elaborate it...
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,439
Helped
14,445
Reputation
29,154
Reaction score
13,245
Trophy points
1,393
Location
Bochum, Germany
Activity points
284,488
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.
 

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
Thanks for your responses,

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

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
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top