jeudi 15 septembre 2016

Random number, who's range is an array's elements

Being new to C, I'm trying to become familiar with the random number generator. I know how to get a random number between a certain interval (Like 1 and 100), but I'm curious as to if it's possible to get a random number that's range is inside an array's elements? Would I use rand() for this? I tried searching for some answers online to this challenge, but came up short in finding a solution. An example, if I had an array:

Array[10] = {50,26,29,10,78,12,45,83,39,55};

And I wanted to create a random number that's ending value is a number in the array, how would I do this in C?




Aucun commentaire:

Enregistrer un commentaire