vendredi 15 mars 2019

Random Number generator with range? C++

I am trying to make a C++ program for my Ebay business that is 15 digits long, but I want the first 5 digits to be the same.

Like ex: 152328476529876 PIN: 1000 152323123642345 PIN: 9433 152321254213432 PIN: 3222

I tried making a random number generator, but I cant get it to where the first 5 digits are the same, but the last 10 digits are the same. With a random pin.

#include <iostream>
#include <cstdlib> 
const int maximum_number = 9999999999;
const int minimum_number = 1;
unsigned int i;
const int maximum_pin = 999;
const int minimum_pin = 0;
unsigned int pin;
int main()
{

    // Print 100 random numbers
    for (int count = 0; count <= 1000; ++count)
    {
        const int new_number = (rand() % (maximum_number - minimum_number)) + maximum_number;
        const int new_pin = (rand() % (maximum_pin - minimum_pin)) + maximum_pin;
        std::cout << "15232" << new_number << " Pin : "<< new_pin << "\n";
    }

    return 0;
152321410094708 Pin : 1384

152321410073128 Pin : 1567 etc

The problem I am having is that the first 5 numbers are the same, which is how I want it, but then the 14100 remains the same and should be randomized as well, not just the last 5 digits...

Plus the pins only stay at 1000, they never go above 1999 etc.




Aucun commentaire:

Enregistrer un commentaire