vendredi 14 février 2020

Random numbers from specific range

I want to display random numbers specific range [from, to]. Following code writes out the value but something is not working properly:

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int draw(int from_to, int to_from)
{
    return (rand()%to_from)+from_to;
}
int main()
{
    srand(time(NULL));
    int start,stop;
    cout << "First number: " << endl;
    cin >> start;
    cout << "Last number: " << endl;
    cin >> stop;
    int x=20;
    do
    {
        cout << draw(start,stop) << endl;
        x--;
    } while(x>0);

    return 0;
}



Aucun commentaire:

Enregistrer un commentaire