Skip to content
Create a gist now

Instantly share code, notes, and snippets.

3D pseudorandom number generator (1st try)
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) {
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]+", ");
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])+", ");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.