1515#include " ../structures/Cloud.h"
1616#include " ../structures/SnowFlake.h"
1717#include " ../main.h"
18+ #include " ../utils/Utils.h"
1819
1920
2021Chunk::Chunk (int chunk_x, int chunk_z, BiomeType *biome) {
@@ -24,7 +25,7 @@ Chunk::Chunk(int chunk_x, int chunk_z, BiomeType *biome) {
2425
2526
2627 // PerlinNoise Setup
27- uint32_t seed = rand ( );
28+ uint32_t seed = utils::random (RAND_MAX );
2829 double frequency = 0.1 ;
2930 int octaves = 4 ;
3031 const siv::PerlinNoise perlin (seed);
@@ -123,7 +124,7 @@ Chunk::Chunk(int chunk_x, int chunk_z, BiomeType *biome) {
123124 key = std::to_string (this ->x + 1 ) + " _" + std::to_string (this ->z );
124125 if (worldPtr->chunks .count (key) > 0 ) {
125126 if (this ->biome != worldPtr->chunks [key]->biome ) {
126- int random_number = rand ( ) % 100 ;
127+ int random_number = utils::random (RAND_MAX ) % 100 ;
127128 int prob_actual_next_ground = 0 ;
128129
129130 if (i == CHUNK_SIZE - 1 ) prob_actual_next_ground = 80 ;
@@ -138,7 +139,7 @@ Chunk::Chunk(int chunk_x, int chunk_z, BiomeType *biome) {
138139 key = std::to_string (this ->x ) + " _" + std::to_string (this ->z + 1 );
139140 if (worldPtr->chunks .count (key) > 0 ) {
140141 if (this ->biome != worldPtr->chunks [key]->biome ) {
141- int random_number = rand ( ) % 100 ;
142+ int random_number = utils::random (RAND_MAX ) % 100 ;
142143 int prob_actual_next_ground = 0 ;
143144
144145 if (j == CHUNK_SIZE - 1 ) prob_actual_next_ground = 80 ;
@@ -153,7 +154,7 @@ Chunk::Chunk(int chunk_x, int chunk_z, BiomeType *biome) {
153154 key = std::to_string (this ->x - 1 ) + " _" + std::to_string (this ->z );
154155 if (worldPtr->chunks .count (key) > 0 ) {
155156 if (this ->biome != worldPtr->chunks [key]->biome ) {
156- int random_number = rand ( ) % 100 ;
157+ int random_number = utils::random (RAND_MAX ) % 100 ;
157158 int prob_actual_next_ground = 0 ;
158159
159160 if (i == 0 ) prob_actual_next_ground = 80 ;
@@ -168,7 +169,7 @@ Chunk::Chunk(int chunk_x, int chunk_z, BiomeType *biome) {
168169 key = std::to_string (this ->x ) + " _" + std::to_string (this ->z - 1 );
169170 if (worldPtr->chunks .count (key) > 0 ) {
170171 if (this ->biome != worldPtr->chunks [key]->biome ) {
171- int random_number = rand ( ) % 100 ;
172+ int random_number = utils::random (RAND_MAX ) % 100 ;
172173 int prob_actual_next_ground = 0 ;
173174
174175 if (j == 0 ) prob_actual_next_ground = 80 ;
@@ -212,13 +213,6 @@ void Chunk::render() {
212213 }
213214}
214215
215- int Chunk::random (int max) {
216- std::random_device seed_gen;
217- std::mt19937_64 engine (seed_gen ()); // 64-bit Mersenne Twister by Matsumoto and Nishimura, 2000
218- std::uniform_int_distribution<> dist (0 , max);
219- return dist (engine);
220- }
221-
222216int Chunk::getBlock (int x, int y, int z) {
223217 return this ->blocks [x][y][z];
224218}
@@ -251,7 +245,7 @@ void Chunk::generateStructures() {
251245
252246 // Get surface_height
253247 int surface_height = this ->heights [i][j];
254- int random_number = this -> random (100 );
248+ auto random_number = utils:: random (100 );
255249
256250 // Trees
257251 if (random_number < this ->biome ->tree_frequency * 100 ) {
@@ -276,7 +270,7 @@ void Chunk::generateStructures() {
276270 // Cloud
277271 for (int i = 5 ; i < CHUNK_SIZE - 5 ; ++i) {
278272 for (int j = 5 ; j < CHUNK_SIZE - 5 ; ++j) {
279- int prob = this -> random (1000 );
273+ int prob = utils:: random (1000 );
280274 if (prob < 50 ) {
281275 int surface_height = 0 ;
282276 for (int k = 0 ; k < CHUNK_HEIGHT; ++k) {
0 commit comments