Pseudo Randomization - muneeb-mbytes/computerArchitectureCourse GitHub Wiki

What is Pseudo-random number?

A pseudorandom sequence of numbers seems random, even though it's created by a predictable and repeatable process.

Why is it called Pseudorandom?

Random numbers generated by software are not genuinely random; instead, they are pseudorandom. This is because computers use predictable algorithms based on a specific distribution. These numbers are not secure because they depend on deterministic and predictable algorithms.

What is random number?

A random number is a value selected by chance from a particular distribution. These numbers should ideally be independent, meaning there's no connection between one number and the next

Difference between random and pseudorandom number?

Property Random Pseudorandom
Approach Extract randomness from physical phenomena and introduce in computer Algorithm of mathematical formula later translated into relatively bits of programming code
Efficiency Slow response in generating numbers Fast response in generating numbers
Determinism Sequence of numbers cannot be reproduced Sequence of numbers can be reproduced

Types of Pseudorandomization

1.$urandom( )

The system function $urandom provides a mechanism for generating pseudorandom numbers. The function returns a new 32-bit random number each time it is called. The number shall be unsigned.

2.$random( )

The system function $random provides a mechanism for generating pseudorandom numbers. $random() is same as $urandom() but it generates signed numbers.

3.$urandom_range( )

The $urandom_range() function returns an unsigned integer within a specified range.

4.std::randomize()

It is also called a Scope-Randomize Function. Scope randomize gives you the ability to randomize variables that are not members of a Class and even multiple variables can be randomized at the same time.

Example:

module pseudorandomization();
integer a; // integer is a signed data type 
logic [2:0] b;// logic is a unsigned data type
byte c;  //byte is a signed data type 
bit [4:0] d  ;// bit is an unsigned data type  
initial begin 
a = $random();
b = $urandom();
c= $urandom_range(4,2); 
std::randomize (d);

$display ("a=$random() - Returns 32 bit signed random variable");
$display("Random Value of a  =  %0d",a);
$display("--------------------------------------------------------------------");

$display("b = $urandom() - Returns unsigned random value .");
$display("Random Value of b = %0d",b);
$display("--------------------------------------------------------------------");

$display ("c = $random_range(4,2) Returns the random number between 4 and 2"); 
$display("Random value of c = %0d",c);
$display("--------------------------------------------------------------------");
  
$display ("d = std::randomize (d) // Return 5 bit unsigned random number"); 
$display("Random value of d = %0d",d);
$display("--------------------------------------------------------------------");
end 
                                     
endmodule:pseudorandomization

Output

Screenshot 2023-12-14 103404