Generate Random Numbers excluding a certain range of values- C# -
Generate Random Numbers excluding a certain range of values- C# -
i have 4 batches:
10000-30000 30001-50000 50001-70000 71000-99999
i have generate 500 random numbers followings groups excluding values {70000-71000}
my code this. datagrid shows 500 records has numbers between {70-71k}.i need calculate count not giving me required "500" count because random numbers getting generated between {70-71k} need exclude.
int i=10000, j=99999; int batch1count = 0, batch2count = 0, batch3count = 0, batch4count = 0; private void button1_click(object sender, eventargs e) { seek { this.datagridview1.rows.clear(); string prefix = combobox1.selectedvalue.tostring(); switch (prefix) { case "1": prefix = "usn"; break; case "2": prefix = "dot"; break; case "3": prefix = "usaf"; break; case "4": prefix = "cov"; break; } (int k = 0; k < 500; k++) { random random = new random(datetime.utcnow.millisecond); //generate random values int result = random.next(i,j); thread.sleep(1); if (result >= 70000 && result <= 71000) { k=k-1; } else { //add prefix generated random value string key = prefix + result; datagridviewrow row = new datagridviewrow(); row.createcells(datagridview1); row.cells[0].value = key; this.datagridview1.rows.add(row); thread.sleep(3); if (result >= 10000 && result <= 30000) { thread.sleep(1); batch1count++; } else if (result >= 30000 && result <= 50000) { thread.sleep(1); batch2count++; } else if (result >= 50000 && result <= 70000) { thread.sleep(1); batch3count++; } else if (result >= 71000 && result <= 99999) { thread.sleep(1); batch4count++; } } } } grab (exception ex) { } }
can't utilize random class it?
the random
class has next(int, int)
method generates random number between specified values. generate 1 , if in {70k-71k} range, generate one.
c#
Comments
Post a Comment