27 lines
803 B
C#
27 lines
803 B
C#
namespace CPUSimulation
|
|
{
|
|
public class Utils
|
|
{
|
|
static Random _random = new Random();
|
|
public static Word GenerateRandomWord(int byteCount)
|
|
{
|
|
byteCount = _random.Next(1, byteCount + 1);
|
|
//Console.WriteLine($"Generating random word with {byteCount} bytes.");
|
|
Byte[] bytes = new Byte[byteCount];
|
|
for (int i = 0; i < byteCount; i++)
|
|
{
|
|
bytes[i] = GenerateRandomByte();
|
|
}
|
|
return new Word(bytes);
|
|
}
|
|
public static Byte GenerateRandomByte()
|
|
{
|
|
Bit[] bits = new Bit[8];
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
bits[i] = new Bit(_random.Next(2) == 1);
|
|
}
|
|
return new Byte(bits);
|
|
}
|
|
}
|
|
} |