Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Good day, i am having little challenge
i am generating a random Number using
C#
// to generate the random Number
  int lbl =  rand.Next(10, 99); // gives me random Numbers
// now i want to loop them so that i can atleast 10 different random Numbers at  once and have it
displayed in a gridview. Please how do i achieve that... thanks for your time. i do appreciate<small></small>
Posted

1 solution

Try this Code:

C#
var chars = "0123456789";
 var random = new Random();
var result = new string(Enumerable.Repeat(chars, 2).Select(s => s[random.Next(s.Length)]).ToArray());
 
Share this answer
 
v2
Comments
Member 10835026 18-Jul-14 9:04am    
thanks but the code you provided only enlist the record in char in the grid view like this
1
2
but i want it to appear like this in the grid view
122
143
213
just a random number... how can i achieve thar... thanks very much for your lovely time
King Fisher 18-Jul-14 9:18am    
Change this Repeat(char,3) and var chars = "0123456789";
Member 10835026 18-Jul-14 9:30am    
thanks what you gave can simply be achieved via using rand.next(1000, 9999)
but i want to use for loop to have the numbers generated many times like sey 10 times instead of generating only once

for (int i = 0; i < 10; i++)
{
int lbl = rand.Next(1000, 999);

LblNumber.Text = lbl.ToString();
}
but the code above only generate one i want the to be upto 10 at once like this
123
132
234
254 and so on

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900