0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have 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" ; 
  }
}

https://github.com/tnagai-github/RNG_uniform_distribution

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?