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.

System Verilog rand and randc

Status
Not open for further replies.

sam33r

Member level 2
Joined
Jan 24, 2011
Messages
52
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
NC
Activity points
1,576
Hi,

Rand generates same iteration of randomized values again and again.
randc randomly iterates over all the values in the range and no value is repeated within an iteration.

Now can we generate the functionality of randc using only rand keyword. ?
 

Hi,

maybe you can do something like this.

Make a list of as many elements as the size of the range in randc
e.g. randc has a range of 0..7 you need 8 elements

each element has an index. This index is going from 0 ... 7
each element has a weight. This can be a real number between 0.0 ... 1.0

now fill your list. For the idx use your range. For the weight you can use the rand function
e.g. you will get
E[0].idx = 0; E[0].weight = 0.453;
E[1].idx = 1; E[1].weight = 0.150;
E[2].idx = 2; E[2].weight = 0.934;
E[3].idx = 3; E[3].weight = 0.443;
E[4].idx = 4; E[4].weight = 0.109;
E[5].idx = 5; E[5].weight = 0.034;
E[6].idx = 6; E[6].weight = 0.657;
E[7].idx = 7; E[7].weight = 0.234;

now you can sort your list by the the weight
in may example you will get
E[0].idx = 5; E[0].weight = 0.034;
E[1].idx = 4; E[1].weight = 0.109;
E[2].idx = 1; E[2].weight = 0.150;
E[3].idx = 7; E[3].weight = 0.234;
E[4].idx = 3; E[4].weight = 0.443;
E[5].idx = 0; E[5].weight = 0.453;
E[6].idx = 6; E[6].weight = 0.657;
E[7].idx = 2; E[7].weight = 0.934;

If you now use the idx of your sorted list you have a randc function
In may example you get 5,4,1,7,3,0,6,2


best regards
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top