mardi 3 août 2021

How do I "surpass" the int function of C++

Alright so, I'm a noob first of all. I started studying code (in C++), and I want to make a random number generator. It's great and all, but as far as I've observed, the generated numbers never exceed the "int" limit of 32768, even tho my variables are all "unsigned long long" (I'm pretty sure that's how you get the largest pool of numbers). I'm pretty sure it's something small, but it;s been bothering me for a day, and I really need answers. Here's how my current code looks like :

#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
    unsigned long long n,m,r,mx;
    cout<< "Please Enter The Number Of Desired Randomly Generated Numbers : ";
    cin>>m;
    cout<< "Please Enter An Upper Limit to the Random Numbers : " ;
    cin>>mx;
    srand ( time(NULL) );
    for (int i=1; i<=m ; i++)
    {
        n = rand() % mx;
        cout << n  << endl; 
    }
    cout<< "Rate this Program Out Of 10: ";
    cin >> r;
    cout << r << " " << "/" << "10";
        return 0;
}



Aucun commentaire:

Enregistrer un commentaire