c# - How do I order the digits 1-10 randomly into an array and then call each part of the array one at a time? -
so basically, need have numbers 1-10 randomly ordered upon startup array, , on when form loads, should load first number. each time user clicks button, load info associated next number. code, reason generates number not integer lot.
random rng = new random(10); int[] questionorder = new int[10]; (int = 0; < questionorder.length; i++) { int temp = rng.next(1,10); while(!(questionorder.contains(temp))) { questionorder[i] = temp; } }
each time generates number 1 - 10 , checks if has been stored in array, if not, stores , runs again.
for reason, generating numbers not integers 1 - 10, , cant figure out why.
this work nicely
static void main(string[] args) { random random = new random(); var range = enumerable.range(1, 10).tolist(); int[] rnd = new int[10]; int j = 0; { int = random.next(0, range.count); rnd[j++] = range[i]; range.removeat(i); } while(range.count > 1); rnd[j] = range[0]; }
less cpu intensive using contains in loop
Comments
Post a Comment