LoginSignup
0
0

More than 1 year has passed since last update.

C++のrandomで一様乱数をメルセンヌツイスターで作る例

Posted at
  • メルセンヌツイスターを利用して[0,1)の範囲の乱数を作る最小の例。C++のrandomを利用。
#include <iostream>
#include <random>

#define NSTEP 100

int main(int argc, char *argv[])
{

    //prepare random numbers
    std::random_device seed_gen;
    std::mt19937_64  engine(seed_gen());
    std::uniform_real_distribution<> dist(0,1) ; 
    // [0,1) according to https://cpprefjp.github.io/reference/random/uniform_real_distribution.html
    // or https://www.cplusplus.com/reference/random/uniform_real_distribution/

  for(int i=0; i < NSTEP ; i++){
    std::cout << dist(engine)  << "\n" ; 
  }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0