public
Last active

3D pseudorandom number generator (1st try)

  • Download Gist
Random3D.java
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
import java.util.Random;
 
public class Random3D {
private long seed;
private Random random;
private long[] masks;
public Random3D(long seed) {
random = new Random(seed);
this.seed = seed;
masks = new long[]{random.nextLong(),random.nextLong(),random.nextLong()};
}
public long getSeed(long x, long y, long z) {
long tx = (x^masks[0])<<7;
long ty = (y^masks[1])<<15;
long tz = (z^masks[2])<<31;
long s = this.seed ^ tx ^ ty ^ tz;
return s;
}
public long getLong(long x, long y, long z) {
random.setSeed(this.getSeed(x,y,z));
return random.nextLong();
}
 
public static void main(String[] args) {
int dim = 5;
long[][][] cube0 = new long[1][dim][dim];
long[][][] cube1 = new long[1][dim][dim];
Random3D rnd0 = new Random3D(0);
Random3D rnd1 = new Random3D(1);
int x = 0;
for (int y=0;y<dim;y++)
for (int z=0;z<dim;z++) {
cube0[x][y][z] = rnd0.getLong(x,y,z);
cube1[x][y][z] = rnd1.getLong(x,y,z);
}
for (int y=0;y<dim;y++) {
for (int z=0;z<dim;z++)
System.out.print(cube0[x][y][z]+", ");
System.out.println();
}
System.out.println();
for (int y=0;y<dim;y++) {
for (int z=0;z<dim;z++)
System.out.print((cube0[x][y][z]-cube1[x][y][z])+", ");
System.out.println();
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.