Skip to content

Instantly share code, notes, and snippets.

@roccodev
Last active March 6, 2018 19:04
Show Gist options
  • Select an option

  • Save roccodev/e40435e36602f2941ec9c3e9f0699d97 to your computer and use it in GitHub Desktop.

Select an option

Save roccodev/e40435e36602f2941ec9c3e9f0699d97 to your computer and use it in GitHub Desktop.
RandomUtils - Easy RNG with C++
//
// Created by roccodev on 06/03/18.
//
/*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Given the nature of the class, a copy of the GNU General Public License
* will not be provided and will need to be acquired at <http://www.gnu.org/licenses/>.
*
*
*/
#include <iostream>
#include <random>
#include "RandomUtils.h"
double RandomUtils::randomDouble(double start, double end){
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<double> dist(start, end);
return dist(mt);
}
float RandomUtils::randomFloat(float start, float end) {
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<float> dist(start, end);
return dist(mt);
}
int RandomUtils::randomInt(int start, int end){
return (int) randomDouble(start, end);
}
//
// Created by roccodev on 06/03/18.
//
/*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Given the nature of the class, a copy of the GNU General Public License
* will not be provided and will need to be acquired at <http://www.gnu.org/licenses/>.
*
*
*/
#ifndef PROJNAME_RANDOMUTILS_H
#define PROJNAME_RANDOMUTILS_H
class RandomUtils {
public:
static double randomDouble(double start, double end);
static float randomFloat(float start, float end);
static int randomInt(int start, int end);
};
#endif //PROJNAME_RANDOMUTILS_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment