random num gen

Why am i getting random numbers in between 100,000 and 120,000? I have all the required #includes and seeded the time to NULL.

I want to get the numbers random from 100,000 to 999,999.

1
2
3
4
5
for (int i = 0; i < 25; i++)
	{
		int pass = rand() % 999999 + 100000;
		cout << pass << endl;
	}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <random> // http://en.cppreference.com/w/cpp/numeric/random
#include <ctime>

int main()
{
    // http://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine
    std::mt19937  rng( std::time(nullptr) ) ;

    // I want to get the numbers random from 100,000 to 999,999.
    // http://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution
    std::uniform_int_distribution<int> distribution( 100000, 999999. ) ;

    for( int i = 0 ; i < 25 ; ++i )
    {
        const int pass = distribution(rng) ;
        std::cout << pass << '\n' ;
    }
}

http://coliru.stacked-crooked.com/a/6543a863cfd04017
Last edited on
Topic archived. No new replies allowed.