pseudo number generator with a range

closed account (oNRiz8AR)
.....................
Last edited on
I believe to do that you do:

9999*rand() + 102
closed account (oNRiz8AR)
where.... indicate with the line of code please.
line 14

cout <<(9999* rand() +102)<< endl;
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>

using namespace std;

int getRand(int from, int to)
{
    return from + rand() % (to - from + 1);
}

int main()
{
    srand(time(0));

    const int lowerLimit = 10;
    const int upperLimit = 15;
    
    for (int nCount=0; nCount < 30; ++nCount)
    {
        cout << setw(6) << getRand(lowerLimit, upperLimit) << endl;

        if ((nCount+1) % 5 == 0)
            cout << endl;
    }
}

Change the values of lowerLimit and upperLimit as required.
Last edited on
Topic archived. No new replies allowed.