Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

generate random ints and floats

#include <random>
#include <iostream>

int main() {
  // 1. The random device
  std::random_device rd;
  // 2. The "Mersenne Twister" random engine
  std::mt19937 gen(rd());
  // 3. A random distribution
  std::uniform_int_distribution<int> dist(1, 20);

  for (int i = 0; i < 10; i ++) {
    std::cout << dist(gen) << " ";
  }
  std::cout << "
";
}

Output:
16 8 11 9 9 13 9 4 13 9 
Source by cppbyexample.com #
 
PREVIOUS NEXT
Tagged: #generate #random #ints #floats
ADD COMMENT
Topic
Name
2+7 =