I am in a programming class and I need to know how to create a random number generator, but the number selected can not repeat.... ever.How do you create an asp function that gives a random number, but it can not repeat that number?
This sounds like a trick question. To do this you would have to keep a record of every used number and if it ever came up you would discard it and get another.
But the point is that when you do this it's no longer random. In this sense random is synonymous with ';any';, at least within the given set.
So, as soon as you disallow certain numbers you've tossed 'random' out the window.How do you create an asp function that gives a random number, but it can not repeat that number?
your need to create a variables for every possiblity
var1, var2, var3, etc.
then
number_range(lowest, highest, num) // number
while (num == var1) || (num == var2) etc // check to see if its in a var
number_range(lowest, highest, num) // if it is reroll number
// then stick it in the next empy varable
If var1 == null
var1 = num;
else if var2 == null
var2 = null; // and so on and so on.
/*
You can later play around with the data to get it to output to whever in the right order you wanted it to be displayed in etc.
*/
No comments:
Post a Comment