Gistrec icon

C++ STL Random

Gistrec | PRO | 03/02/20 10:20:44 AM UTC | 0 ⭐ | 734 👁️ | Never ⏰ | []
C++ |

530 B

|

None

|

0 👍

/

0 👎

#include <iostream>
#include <random>
 
 
int main() {
    using ElemT = float;
 
    // Predefined random number generators
    // https://en.cppreference.com/w/cpp/numeric/random
    std::mt19937_64 engine{ std::random_device{}() };
 
    // Random number distributions
    // https://en.cppreference.com/w/cpp/numeric/random
    std::normal_distribution<ElemT>      normal{ 0.0f, 0.5f };
    std::exponential_distribution<ElemT> exp{ 1.0f }; 
 
    for (auto i : std::vector<ElemT>(10, 0.0f)) {
        std::cout << exp(engine) << std::endl;  
    }
 
    return 0;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎