Created
August 27, 2014 14:46
-
-
Save ashwin/bf89d957b97502236ed9 to your computer and use it in GitHub Desktop.
Random number generation in C++11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <limits> | |
#include <random> | |
int main() | |
{ | |
std::default_random_engine eng((std::random_device())()); | |
std::uniform_int_distribution<int8_t> idis(0, std::numeric_limits<int8_t>::max()); | |
for (int i = 0; i < 10; ++i) | |
{ | |
int8_t v = idis(eng); | |
std::cout << (int32_t) v << std::endl; | |
} | |
std::uniform_real_distribution<float> fdis(0, 2.0); | |
for (int i = 0; i < 10; ++i) | |
{ | |
float v = fdis(eng); | |
std::cout << v << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment