Generating Random Numbers

I know how to generate random numbers from 0-100 and such. But how would I generate a random number from 50 to 100?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <random>
#include <ctime>

int random_value_in_range( int minval, int maxval ) // C++11
{
    // http://en.cppreference.com/w/cpp/numeric/random
    static std::mt19937 rng( std::time(nullptr) ) ;
    return std::uniform_int_distribution<int>( minval, maxval )(rng) ;
}

int main()
{
    for( int i = 0 ; i < 30 ; ++i ) std::cout << random_value_in_range( 50, 100 ) << ' ' ;
    std::cout << '\n' ;
}

http://coliru.stacked-crooked.com/a/bedc8f378a5b3d06
Topic archived. No new replies allowed.