diff --git a/src/noise.cpp b/src/noise.cpp
index 443c405cec8030a88a1b0b2175b26b3761356e09..2948fb765c509fb424fec0496f27b53e1d641d4c 100644
--- a/src/noise.cpp
+++ b/src/noise.cpp
@@ -90,6 +90,9 @@ u32 PcgRandom::next()
 
 u32 PcgRandom::range(u32 bound)
 {
+	// If the bound is 0, we cover the whole RNG's range
+	if (bound == 0)
+		return next();
 	/*
 	If the bound is not a multiple of the RNG's range, it may cause bias,
 	e.g. a RNG has a range from 0 to 3 and we take want a number 0 to 2.
diff --git a/src/unittest/test_random.cpp b/src/unittest/test_random.cpp
index 20cfca3343cfefc2f7b97d5ebf327442eb9167d0..bbee577193d90275ee1b412f3df1247fb63e4462 100644
--- a/src/unittest/test_random.cpp
+++ b/src/unittest/test_random.cpp
@@ -101,6 +101,9 @@ void TestRandom::testPcgRandomRange()
 
 	EXCEPTION_CHECK(PrngException, pr.range(5, 1));
 
+	// Regression test for bug 3027
+	pr.range(pr.RANDOM_MIN, pr.RANDOM_MAX);
+
 	for (u32 i = 0; i != 32768; i++) {
 		int min = (pr.next() % 3000) - 500;
 		int max = (pr.next() % 3000) - 500;