samedi 11 février 2017

Random number generator choosing only between given few numbers in C#.(Help please)

I know how to choose random numbers between a two numbers. However I don't know how to make it to choose a random number that I tell it. This is what I am trying to do. I have 5 integers.

int Hamburger = 5;
int Sandwich = 7;
int ChickenSalad = 10;
int Pizza = 15;
int Sushi = 20;

5,7,10,15,20 are the prices of each food and I want to make it so that it would choose a random number from 5,7,10,15,20. I am new to C# so I don't really know much about this. I found this

randomNoCorss = arr[r.Next(arr.Length)];

in another post but I don't understand it and I don't know how I can put it in my code. Thanks.




Aucun commentaire:

Enregistrer un commentaire