/
system.java
59 lines (44 loc) · 1.23 KB
/
system.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Arbitrary mapping algorithm
*
* AUTHOR Jayed S. Rafi
* DATE August 2021
*
* PURPOSE: randomize array values
*/
public class system {
// main
// interface to test the system
public static void main(String[] args) {
int[] list = {1,2,3,4,5,6,7,8,9};
print(list,randomize(list));
}//end main
/**
* PURPOSE: randomization
* INPUT PARAMETERS:
* initial array
* OUTPUT PARAMETERS:
* returns the modified array
*/
public static int[] randomize ( int[] list ){
final int SIZE = list.length; //length of initial array
final int RANDOM_CONSTANT = (int)(Math.random()*SIZE);
int[] temp = new int[SIZE]; //temporary array
for(int i=0; i<SIZE; i++){
int index = (i+RANDOM_CONSTANT)%SIZE; //index
temp[index] = list[i]; //update
}
return temp;
}//End MapArray
/**
* PURPOSE: prints the contents of initial and modified array
* INPUT PARAMETERS:
* initial and modified array
*/
public static void print( int[] list, int[] mod){
System.out.println("[ Index ] [ Base list ] [ Arbitrary Mapping Algorithm ] ");
for(int i=0; i<list.length; i++){
System.out.println("Index["+i+"] = "+" [ "+list[i]+" ] "+" [ "+mod[i] +" ]");
}
}//end print
}//end system