Generate random number between 0 to 10000 in c# -
i'm using c# generate 1000 random number between 0 10000. output need 2 decimal places , , dispaly following
1 18.92 2 874.32 3 7182.56
here code :
random random = new random(); float randomnumber = random.next(0, 10001); string rndnumber = randomnumber.tostring("0.00"); (int = 1; i<= 1000; i++) { (int count = 1; count <= 1000; count++) { writer.write("{0},\n {0:0.0}", count, rndnumber); }
but far output this:
1, 1.02, 2.03, 3.04, 4.05, 5.06, 6.07, 7.08, 8.09, 9.010, 10.011, 11.012
what did missing?
i figure out myself , use double
, math.round
2 decimal
here answer:
random random = new random(); (int count = 1; count <= 1000; count++) { double r = math.round((random.nextdouble() * 10001),2); writer.writeline("{0} \n {1}",count, r); }
Comments
Post a Comment