Search
 
SCRIPT & CODE EXAMPLE
 

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 
Comment

random number generator for floats

float r3 = LO + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(HI-LO)));
Comment

PREVIOUS NEXT
Code Example
Cpp :: find maximum contiguous Sub arrays 
Cpp :: check if number is positive or negative in cpp 
Cpp :: multiple inheritance c++ 
Cpp :: std::hash 
Cpp :: std::filesystem::path to std::string 
Cpp :: algorithm map values 
Cpp :: how to show c++ binary files in sublime text 
Cpp :: ue_log example 
Cpp :: return value from a thread 
Cpp :: binary algebra cpp 
Cpp :: stack in c++ data structure 
Cpp :: std 
Cpp :: c++ count inversions merge sort 
Cpp :: determining whether a array is a subsequence of another array 
Cpp :: factorial MOD 998244353 
Cpp :: can derived class access base class non-static members without object of the base class 
Cpp :: npm wasm 
Cpp :: flutter websocket auto reconnect 
Cpp :: MPI_File_seek 
Cpp :: QMetaObject_invokeMethod 
Cpp :: tutti i tipi di equazioni trigonometriche 
Cpp :: In every C++ program: 
Cpp :: c++ projects 
Cpp :: Determine if map contains a value for a key c++ 
Cpp :: batch to exe 
Cpp :: aliasing c++ 
Cpp :: c++ influenced 
C :: pointer to a structure in c 
C :: find factors of a number in c 
C :: sum of list in C 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =