Hey everyone, I’m running into a strange issue with my dungeon generator.
I’m using a central java.util.Random object with a fixed seed, which I pass down to my logic classes (RoomLogic, PathLogic, etc.). Theoretically, it should be fine, but I keep getting repetitive, "unnatural" patterns in the layout that I can't explain.
The Setup: Standard Random object passed via a Config class.
The Issue: The distribution feels "off" almost like there's a bias in how rooms are placed.
My questions:
Is java.util.Random known for** poor distribution** in 2D/3D grid generation?
Should I switch to something like a Mersenne Twister or XorShift?
Or is this more likely a "Modulo Bias" / logic error in how I map coordinates?
Has anyone dealt with "non-random" looking randomness before? Any advice on how to debug this would be huge. Thanks!
public boolean roomPlacement(ZoneConfig zoneConfig) {
//---PLATZIERUNGS-VERSUCHE---//
for (int i = 0; i < maxTries; i++) {
//---ZONE ROTIEREN---//
Zone rotatedZone = zoneConfig.getZone().get(Direction.getRandomDirection(random));
ZoneSize size = rotatedZone.getZoneSize();
//---GRID GRENZEN BERECHNEN---//
int minX = 0 - size.getxMin();
int maxX = g.xSize - 1 - size.getxMax();
int minY = 0 - size.getyMin();
int maxY = g.ySize - 1 - size.getyMax();
int minZ = 0 - size.getzMin();
int maxZ = g.zSize - 1 - size.getzMax();
//---ZUFÄLLIGE POSITION---//
int x = random.nextInt(maxX - minX + 1) + minX;
int y = random.nextInt(maxY - minY + 1) + minY;
int z = random.nextInt(maxZ - minZ + 1) + minZ;
//---FÜR TOP ODER BOTTOM LAYER ROOMS---//
if (zoneConfig.getLayer() == Layer.BOTTOM) {
z = size.getzMin()*-1;
for (int j = 0; j < size.getDiameterZ(); j++) {
if(g.getFillRatioOnZ(j) > targetFillRatio) {
return false;
}
}
}else if(zoneConfig.getLayer() == Layer.TOP) {
z = g.zSize - size.getzMax() - 1;
for (int j = g.zSize; j > size.getDiameterZ(); j--) {
if(g.getFillRatioOnZ(j-1) > targetFillRatio) {
return false;
}
}
}
//---PLATZIERUNG PRÜFEN---//
if (g.canPlace(rotatedZone, x, y, z)) {
g.addRoom(rotatedZone, x, y, z);
Log.info("Placed Room after [" + i + "] tries.");
return true;
}
}
//---KEINE PLATZIERUNG MÖGLICH---//
Log.warning("Couldnt Place Room after [" + maxTries + "] tries.");
return false;
}