Package hlcd.operations
Class RandomMatrixGenerator
java.lang.Object
hlcd.operations.RandomMatrixGenerator
Generates a random matrix based on the parameters specified.
//minimal example to execute this class:
public static void main(String[] args) {
System.out.println("Running RandomMatrixGenerator...");
RandomMatrixGenerator rmg = new RandomMatrixGenerator((byte) 20);
rmg.printMatrix(" ", true, Style.DECIMAL, true);
System.out.println("RandomMatrixGenerator completed.");
}- Since:
- 1.8
- Version:
- 1.0 (February 10th, 2022)
- Author:
- Maysara Al Jumaily
-
Constructor Summary
ConstructorsConstructorDescriptionInitializes a random matrix with a random base, random \(k\) and \(n\) values.RandomMatrixGenerator(byte size)Create a random square matrix with the assumption that the base is \(4\).RandomMatrixGenerator(byte n, byte k, byte base)Randomly initializes the matrix based on the parameters specified.RandomMatrixGenerator(byte minN, byte maxN, byte minK, byte maxK, byte base)Randomly creates a matrix based on the range of \(n\) and range of \(k\) specified.RandomMatrixGenerator(long[] matrixArray, byte n, byte k, byte base)Initializes the current matrix array to the specified array and the other specified parameters to the current ones. -
Method Summary
Modifier and TypeMethodDescriptionlong[]convertByteArrayToLongArray(byte[] matrixArray)Converts the specified byte matrix array to a long matrix array.byte[]convertLongArrayToByteArray(long[] matrixArray)Converts the specified long matrix array to a byte matrix array.bytegetBase()Returns the base which could either be \(2\) or \(4\).bytegetK()Returns the number of row in the matrix array.Returns the current matrix array as aMatrixtype.long[]Returns the current matrix array.long[]Returns a clone of the current matrix array.bytegetMaxK()Returns the maximum value of the \(k\) range.bytegetMaxN()Returns the maximum value of the \(n\) range.bytegetMinK()Returns the minimum value of the \(k\) range.bytegetMinN()Returns the minimum value of the \(n\) range.bytegetN()Returns the number of columns in the matrix array.voidPrints the matrix on console using the following default properties: the columns are separated by a space, the brackets are added, the style is base 10 and the size is shown.voidprintMatrix(boolean addBrackets, Style style, boolean showSize)Prints the matrix on console while using the space character as the delimiter between the columns.voidprintMatrix(long[] matrixArray, byte n, byte base, String delimiter, boolean addBrackets, Style style, boolean showSize)Prints the matrix array specified on console using the parameters passed.voidprintMatrix(String delimiter, boolean addBrackets, Style style, boolean showSize)Prints the matrix array specified on console using the parameters passed.voidPrints the \(n\), \(k\) and base values.byte[][]Returns a 2-D array of the current 1-D matrix array.byte[][]to2DArray(long[] matrixArray, byte n, byte k, byte base)Returns a 2-D array of the 1-D matrix array specified.
-
Constructor Details
-
RandomMatrixGenerator
public RandomMatrixGenerator()Initializes a random matrix with a random base, random \(k\) and \(n\) values. -
RandomMatrixGenerator
public RandomMatrixGenerator(byte size)Create a random square matrix with the assumption that the base is \(4\).- Parameters:
size- the size of the random matrix to be created
-
RandomMatrixGenerator
public RandomMatrixGenerator(byte n, byte k, byte base)Randomly initializes the matrix based on the parameters specified.- Parameters:
n- the length of each vector in the matrixk- the dimension of the matrixbase- the base which could either be \(2\) or \(4\)
-
RandomMatrixGenerator
public RandomMatrixGenerator(long[] matrixArray, byte n, byte k, byte base)Initializes the current matrix array to the specified array and the other specified parameters to the current ones.- Parameters:
matrixArray- the matrix arrayn- the length of each vector in the matrixk- the dimension of the matrixbase- the base which could either be \(2\) or \(4\)
-
RandomMatrixGenerator
public RandomMatrixGenerator(byte minN, byte maxN, byte minK, byte maxK, byte base)Randomly creates a matrix based on the range of \(n\) and range of \(k\) specified.- Parameters:
minN- the smallest \(n\) value to be generatedmaxN- the largest \(n\) value to be generatedminK- the smallest \(k\) value to be generatedmaxK- the largest \(k\) value to be generatedbase- the base which could either be \(2\) or \(4\)
-
-
Method Details
-
convertByteArrayToLongArray
public long[] convertByteArrayToLongArray(byte[] matrixArray)Converts the specified byte matrix array to a long matrix array.- Parameters:
matrixArray- the byte matrix array to be converted to long matrix array- Returns:
- the specified matrix array as a long matrix array
-
convertLongArrayToByteArray
public byte[] convertLongArrayToByteArray(long[] matrixArray)Converts the specified long matrix array to a byte matrix array.- Parameters:
matrixArray- the long matrix array to be converted to byte matrix array- Returns:
- the specified matrix array as a byte matrix array
-
printParameters
public void printParameters()Prints the \(n\), \(k\) and base values. -
printMatrix
public void printMatrix()Prints the matrix on console using the following default properties: the columns are separated by a space, the brackets are added, the style is base 10 and the size is shown. -
printMatrix
Prints the matrix on console while using the space character as the delimiter between the columns.- Parameters:
addBrackets- should surround the matrix with bracketsstyle- the style format which could either be binary, quaternary, decimal or \(\LaTeX\)showSize- should the dimension of the matrix be displayed in the bottom-right corner
-
printMatrix
Prints the matrix array specified on console using the parameters passed.- Parameters:
delimiter- the delimiter used to separate the columnaddBrackets- should surround the matrix array with bracketsstyle- the style format which could either be binary, quaternary, decimal or \(\LaTeX\)showSize- should the dimension of the matrix array be displayed in the bottom-right corner
-
printMatrix
public void printMatrix(long[] matrixArray, byte n, byte base, String delimiter, boolean addBrackets, Style style, boolean showSize)Prints the matrix array specified on console using the parameters passed.- Parameters:
matrixArray- the matrix array to be printed on consolen- the length of each vector in the matrixbase- the base of the code which could either be \(2\) or \(4\)delimiter- the delimiter used to separate the columnsaddBrackets- should surround the matrix with bracketsstyle- the style format which could either be binary, quaternary, decimal or \(\LaTeX\)showSize- should the dimension of the matrix be displayed in the bottom-right corner
-
to2DArray
public byte[][] to2DArray()Returns a 2-D array of the current 1-D matrix array.- Returns:
- a 2-D array of the current 1-D matrix array
-
to2DArray
public byte[][] to2DArray(long[] matrixArray, byte n, byte k, byte base)Returns a 2-D array of the 1-D matrix array specified.- Parameters:
matrixArray- the 1-D matrix array to transform to a 2-D matrix arrayn- the number of columns in the matrix array specifiedk- the number of rows in the matrix array specifiedbase- the base which can either be \(2\) or \(4\)- Returns:
- a 2-D array equivalent of the matrix array specified
-
getMatrixArray
public long[] getMatrixArray()Returns the current matrix array.- Returns:
- the current matrix array
-
getMatrixArrayClone
public long[] getMatrixArrayClone()Returns a clone of the current matrix array.- Returns:
- a clone of the current matrix array
-
getN
public byte getN()Returns the number of columns in the matrix array.- Returns:
- the number of columns in the matrix array
-
getK
public byte getK()Returns the number of row in the matrix array.- Returns:
- the number of row in the matrix array
-
getBase
public byte getBase()Returns the base which could either be \(2\) or \(4\).- Returns:
- the base which could either be \(2\) or \(4\)
-
getMinK
public byte getMinK()Returns the minimum value of the \(k\) range.- Returns:
- the minimum value of the \(k\) range
-
getMaxK
public byte getMaxK()Returns the maximum value of the \(k\) range.- Returns:
- the maximum value of the \(k\) range
-
getMinN
public byte getMinN()Returns the minimum value of the \(n\) range.- Returns:
- the minimum value of the \(n\) range
-
getMaxN
public byte getMaxN()Returns the maximum value of the \(n\) range.- Returns:
- the maximum value of the \(n\) range
-
getMatrix
Returns the current matrix array as aMatrixtype.- Returns:
- the current matrix array as a
Matrixtype
-