| Random Number Generators | |
| Types | |
| dist_bin | Defines the structure of a random distribution bin. |
| random_util | Provides a utility function to generate random numbers. |
| Functions | |
| random_bool | static Returns a randomized Boolean value based on the specified percentage. |
| random_2_bin_num | Provides a random number using two distribution bins. |
| Properties | |
| db | Random distribution bins. |
| val | rand The randomized value. |
| Functions | |
| new | Create a random number object. |
| random_4_bin_num | Provides a random number using four distribution bins. |
| Properties | |
| db | Random distribution bins. |
| val | rand The randomized value. |
| Functions | |
| new | Create a random number object. |
| random_8_bin_num | Provides a random number using eight distribution bins. |
| Properties | |
| db | Random distribution bins. |
| val | rand The randomized value. |
| Functions | |
| new | Create a random number object. |
| random_16_bin_num | Provides a random number using sixteen distribution bins. |
| Properties | |
| db | Random distribution bins. |
| val | rand The randomized value. |
| Functions | |
| new | Create a random number object. |
| random_32_bin_num | Provides a random number using thirty-two distribution bins. |
| Properties | |
| db | Random distribution bins. |
| val | rand The randomized value. |
| Functions | |
| new | Create a random number object. |
| random_power_of_2_num | Provides a random number with power-of-two distributions. |
| Properties | |
| min_val | The minimum limit of val. |
| max_val | The maximum limit of val. |
| Functions | |
| new | Create a random number object. |
| random_power_of_10_num | Provides a random number with power-of-ten distributions. |
| Properties | |
| min_val | The minimum limit of val. |
| max_val | The maximum limit of val. |
| Functions | |
| new | Create a random number object. |
class random_util
Provides a utility function to generate random numbers.
| Functions | |
| random_bool | static Returns a randomized Boolean value based on the specified percentage. |
static function bit random_bool( int unsigned true_pct = 50 )
static Returns a randomized Boolean value based on the specified percentage.
| true_pct | optional The probability of the returned value to be randomized to 1 (true). The unit is a percent. The default is 50 (50% true). |
The randomized Boolean value (1 or 0).
bit rb = random_util::random_bool( .true_pct( 70 ) ); // 70% true
class random_2_bin_num
Provides a random number using two distribution bins.
The value of variable n.val is randomzed to between 0 and 9, or 10 and 19 with a weighted ratio of 1-2.
random_2_bin_num n = new();
// min max wt
n.db[0] = '{ 0, 9, 1 }; // bin 0
n.db[1] = '{ 10, 19, 2 }; // bin 1
assert( n.randomize() );
$display( n.val );| Properties | |
| db | Random distribution bins. |
| val | rand The randomized value. |
| Functions | |
| new | Create a random number object. |
class random_4_bin_num
Provides a random number using four distribution bins.
The value of variable n.val is randomzed to between 0 and 9, 10 and 19, 20 and 29, or 30 and 39 with a weighted ratio of 1-2-3-4.
random_4_bin_num n = new();
// min max wt
n.db[0] = '{ 0, 9, 1 }; // bin 0
n.db[1] = '{ 10, 19, 2 }; // bin 1
n.db[2] = '{ 20, 29, 3 }; // bin 2
n.db[3] = '{ 30, 39, 4 }; // bin 3
assert( n.randomize() );
$display( n.val );| Properties | |
| db | Random distribution bins. |
| val | rand The randomized value. |
| Functions | |
| new | Create a random number object. |
class random_8_bin_num
Provides a random number using eight distribution bins.
The value of variable n.val is randomzed to between 0 and 9, 10 and 19, 20 and 29, 30 and 39, 40 and 49, 50 and 59, 60 and 69, or 70 and 79 with a weighted ratio of 1-2-3-4-5-6-7-8.
random_8_bin_num n = new();
// min max wt
n.db[0] = '{ 0, 9, 1 }; // bin 0
n.db[1] = '{ 10, 19, 2 }; // bin 1
n.db[2] = '{ 20, 29, 3 }; // bin 2
n.db[3] = '{ 30, 39, 4 }; // bin 3
n.db[4] = '{ 40, 49, 5 }; // bin 4
n.db[5] = '{ 50, 59, 6 }; // bin 5
n.db[6] = '{ 60, 69, 7 }; // bin 6
n.db[7] = '{ 70, 79, 8 }; // bin 7
assert( n.randomize() );
$display( n.val );| Properties | |
| db | Random distribution bins. |
| val | rand The randomized value. |
| Functions | |
| new | Create a random number object. |
class random_16_bin_num
Provides a random number using sixteen distribution bins. See random_8_bin_num for how to use this class.
| Properties | |
| db | Random distribution bins. |
| val | rand The randomized value. |
| Functions | |
| new | Create a random number object. |
class random_32_bin_num
Provides a random number using thirty-two distribution bins. See random_8_bin_num for how to use this class.
| Properties | |
| db | Random distribution bins. |
| val | rand The randomized value. |
| Functions | |
| new | Create a random number object. |
class random_power_of_2_num extends random_32_bin_num
Provides a random number with power-of-two distributions. This class uses the following pre-populated distribution bins.
// min max wt bin
db = '{ '{ 0, 0, 1 }, // 0
'{ 1, 1, 1 }, // 1
'{ 2, 2, 1 }, // 2
'{ 3, 3, 1 }, // 3
'{ 4, 4, 1 }, // 4
'{ 5, 7, 1 }, // 5
'{ 8, 8, 1 }, // 6
'{ 9, 15, 1 }, // 7
'{ 16, 16, 1 }, // 8
'{ 17, 31, 1 }, // 9
'{ 32, 32, 1 }, // 10
'{ 33, 63, 1 }, // 11
'{ 64, 64, 1 }, // 12
'{ 65, 127, 1 }, // 13
'{ 128, 128, 1 }, // 14
'{ 129, 255, 1 }, // 15
'{ 256, 256, 1 }, // 16
'{ 257, 511, 1 }, // 17
'{ 512, 512, 1 }, // 18
'{ 513, 1023, 1 }, // 19
'{ 1024, 1024, 1 }, // 20
'{ 1025, 2047, 1 }, // 21
'{ 2048, 2048, 1 }, // 22
'{ 2049, 4095, 1 }, // 23
'{ 4096, 4096, 1 }, // 24
'{ 4097, 8191, 1 }, // 25
'{ 8192, 8192, 1 }, // 26
'{ 8193, 16383, 1 }, // 27
'{ 16384, 16384, 1 }, // 28
'{ 16385, 32767, 1 }, // 29
'{ 32768, 32768, 1 }, // 30
'{ 32769, 65535, 1 } }; // 31random_power_of_2_num n = new(); assert( n.randomize() ); $display( n.val );
| Properties | |
| min_val | The minimum limit of val. |
| max_val | The maximum limit of val. |
| Functions | |
| new | Create a random number object. |
function new( int default_val = 0, int min_val = 0, int max_val = 65535 )
Create a random number object.
| default_val | optional The value of val before randomization. The default is 0. |
| min_val | optional The minimum limit of val. The val is randomized to be at least this value. The default is 0. |
| max_val | optional The maximum limit of val. The val is randomized to be at most this value. The default is 65,535. |
class random_power_of_10_num extends random_16_bin_num
Provides a random number with power-of-ten distributions. This class uses the following pre-populated distribution bins.
// min max wt bin
db = '{ '{ 0, 0, 1 }, // 0
'{ 1, 1, 1 }, // 1
'{ 2, 9, 1 }, // 2
'{ 10, 10, 1 }, // 3
'{ 11, 99, 1 }, // 4
'{ 100, 100, 1 }, // 5
'{ 101, 999, 1 }, // 6
'{ 1_000, 1_000, 1 }, // 7
'{ 1_001, 9_999, 1 }, // 8
'{ 10_000, 10_000, 1 }, // 9
'{ 10_001, 99_999, 1 }, // 10
'{ 100_000, 100_000, 1 }, // 11
'{ 100_001, 999_999, 1 }, // 12
'{ 1_000_000, 1_000_000, 1 }, // 13
'{ 1_000_001, 9_999_999, 1 }, // 14
'{ 10_000_000, 10_000_000, 1 } }; // 15random_power_of_10_num n = new(); assert( n.randomize() ); $display( n.val );
| Properties | |
| min_val | The minimum limit of val. |
| max_val | The maximum limit of val. |
| Functions | |
| new | Create a random number object. |
function new( int default_val = 0, int min_val = 0, int max_val = 10_000_000 )
Create a random number object.
| default_val | optional The value of val before randomization. The default is 0. |
| min_val | optional The minimum limit of val. The val is randomized to be at least this value. The default is 0. |
| max_val | optional The maximum limit of val. The val is randomized to be at most this value. The default is 10,000,000. |
Defines the structure of a random distribution bin.
typedef struct { int min_val; int max_val; byte unsigned wt /*= 0*/; } dist_bin
Provides a utility function to generate random numbers.
class random_util
static Returns a randomized Boolean value based on the specified percentage.
static function bit random_bool( int unsigned true_pct = 50 )
Provides a random number using two distribution bins.
class random_2_bin_num
Random distribution bins.
dist_bin db[2]
rand The randomized value.
rand int val
Create a random number object.
function new( int default_val = 0 )
Provides a random number using four distribution bins.
class random_4_bin_num
Random distribution bins.
dist_bin db[4]
rand The randomized value.
rand int val
Create a random number object.
function new( int default_val = 0 )
Provides a random number using eight distribution bins.
class random_8_bin_num
Random distribution bins.
dist_bin db[8]
rand The randomized value.
rand int val
Create a random number object.
function new( int default_val = 0 )
Provides a random number using sixteen distribution bins.
class random_16_bin_num
Random distribution bins.
dist_bin db[16]
rand The randomized value.
rand int val
Create a random number object.
function new( int default_val = 0 )
Provides a random number using thirty-two distribution bins.
class random_32_bin_num
Random distribution bins.
dist_bin db[32]
rand The randomized value.
rand int val
Create a random number object.
function new( int default_val = 0 )
Provides a random number with power-of-two distributions.
class random_power_of_2_num extends random_32_bin_num
The minimum limit of val.
int min_val
The maximum limit of val.
int max_val
Create a random number object.
function new( int default_val = 0, int min_val = 0, int max_val = 65535 )
Provides a random number with power-of-ten distributions.
class random_power_of_10_num extends random_16_bin_num
The minimum limit of val.
int min_val
The maximum limit of val.
int max_val
Create a random number object.
function new( int default_val = 0, int min_val = 0, int max_val = 10_000_000 )