Skip to content
Snippets Groups Projects
Commit 79b7c588 authored by Ian Prins's avatar Ian Prins
Browse files

Implement random.h

parent 12ddb5d6
No related branches found
No related tags found
No related merge requests found
......@@ -6,9 +6,10 @@
class Generator {
public:
Generator();
int getNum(int, int);
int intFromRange(int, int);
double operator()();
private:
std::mt19937 gen;
}
};
#endif
#include <iostream>
#include "libtcod/include/libtcod.hpp"
#include <random>
#include "include/random.h"
#include <vector>
#include <string>
......@@ -20,20 +20,19 @@ int main(int argv, char** args) {
TCODConsole::setCustomFont("assets/terminal-large.png");
//Some stdlib blabber
std::random_device rand_device;
std::mt19937 twister(rand_device());
std::discrete_distribution<> distribution({3, 1});
// Map dimensions (from original Rogue)
uint mapx = 80, mapy = 25;
std::vector<std::vector<int> > map;
Generator rand;
for (uint x = 0; x < mapx; x++) {
map.push_back(std::vector<int>());
for (uint y = 0; y < mapy; y++) {
map[x].push_back(distribution(twister));
int block = rand() < .25 ? 1 : 0;
map[x].push_back(block);
}
}
......
#include <random>
#include "include/random.h"
Generator::Generator() {
gen = std::mt19937(std::random_device()());
}
//inclusive
int Generator::intFromRange(int lower, int upper) {
return std::uniform_int_distribution<>(lower, upper)(gen);
}
double Generator::operator()() {
return std::uniform_real_distribution<>(0, 1)(gen);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment