c# - Increment from 0 to n from a set of numbers a to b -


example:

starting number: 0

finish number: 147

choose random number in range 1-26. increment starting number number, continually getting random number until reach finish number.

that is, if @ 137 means random number has between 1 , 10. when reach 144, between 1 , 3 , on. i've tried using modulo no avail.

example of code i've tried:

int start = 0; int finish = 0; int highest = 26;  while(start <= finish) {     int modulo = start % finish % highest;     int random = (new random()).next(modulo);      start += random; } 

any ideas?

it a lot better essential move random instance out of loop. otherwise values except last few same.

to number in your dynamic range, there random method
next(int minvalueinclusive, int maxvalueexclusive)

int finish = 147;   // untested var generator = new random();  // outside loop while(start < finish)          // stop when equal {     int range = finish-start;     if (range > highest) range = highest;      int random = generator.next(1, range+1);      start += random;      console.write('a' + random - 1);  // check } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -