Last active
August 23, 2016 10:12
-
-
Save limingjie/a26d2e6d4595af95f8bb2b43ae2e10ce to your computer and use it in GitHub Desktop.
Test Random Generator
This file contains hidden or 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
Success time: 0 memory: 3472 signal:0 | |
tester[2054] = 2 | |
tester[24727] = 2 | |
tester[86956] = 2 | |
Success time: 0 memory: 3472 signal:0 | |
tester[12850] = 2 | |
tester[35134] = 2 | |
tester[46743] = 2 | |
tester[87364] = 2 | |
tester[88344] = 2 | |
Success time: 0 memory: 3472 signal:0 | |
tester[33858] = 2 | |
tester[73201] = 2 | |
tester[93769] = 2 | |
Success time: 0 memory: 3472 signal:0 | |
tester[1004] = 2 | |
tester[6958] = 2 | |
tester[77638] = 2 | |
Success time: 0 memory: 3472 signal:0 | |
tester[1004] = 2 | |
tester[6958] = 2 | |
tester[77638] = 2 | |
Success time: 0 memory: 3472 signal:0 | |
tester[29647] = 2 | |
tester[62119] = 2 | |
Success time: 0 memory: 3472 signal:0 | |
tester[4741] = 2 | |
tester[8926] = 2 | |
tester[41015] = 2 | |
tester[45446] = 2 | |
Success time: 0 memory: 3472 signal:0 | |
tester[15781] = 2 | |
tester[39599] = 2 | |
tester[43793] = 2 | |
tester[72914] = 2 | |
tester[73344] = 2 |
This file contains hidden or 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 <random> | |
#include <map> | |
#include <chrono> | |
int main() | |
{ | |
// Random Device | |
std::random_device rd; | |
// Random Generator | |
std::mt19937 generator(rd()); | |
// In case random device does not work, such as under MinGW | |
// std::mt19937 generator(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count()); | |
// Distribution | |
std::uniform_int_distribution<int> distribution(0, 99999); | |
// Generate random numbers | |
std::map<int, int> tester; | |
for (int i = 0; i < 1000; i++) | |
{ | |
tester[distribution(generator)]++; | |
} | |
// Output duplicate random numbers | |
for (const auto& kv : tester) | |
{ | |
if (kv.second > 1) | |
{ | |
std::cout << "tester[" << kv.first << "] = " << kv.second << std::endl; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment