vendredi 26 août 2016

C++ Random number generator from a specific array

I want to be able to generate random numbers from a specific array that I will place. For example: I want to generate a random number from the array {3,8,16,19,22}. its just that there is no pattern in the array that I want to generate.

I was only able to search how to generate a random number from 1-100 using srand() from the video tutorial https://www.youtube.com/watch?v=P7kCXepUbZ0&list=PL9156F5253BE624A5&index=16 but I don't know how to specify the array that it will search from..

btw, my code is similar to this..

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

using namespace std;

int main(int argc, char*argv[])
{
    srand(time(0)); 

    int i =rand()%100+1;0
    cout << i << endl; 
    return 0;
}




Aucun commentaire:

Enregistrer un commentaire