Click here to Skip to main content
16,004,602 members
Please Sign up or sign in to vote.
1.25/5 (4 votes)
See more:
I want a component for show random numbers between 1 to 9.

[EDIT] Title- Adjusted. [/Edit]
Posted
Updated 5-Jan-11 0:51am
v2
Comments
fjdiewornncalwe 5-Jan-11 11:08am    
What part of this homework project have you done already and where did you run into problems. We are here to help you with issues, but not to do the assignments for you.

I am not sure on which component you want to create. But for achieving random nos you could see Random class is there in .Net framework, That you can display random no in any of control as you haven't specified type of your UI so I am not getting much idea on the same.

Like if you want to find random between 1 and 9 then follow following snippets.

C#
private int RandomNumber()
{
Random random = new Random();
return random.Next(1, 10);
}


See THIS[^] article for more.

[Small correction: Upper bound in Random.Next is never reached.]
 
Share this answer
 
v2
Comments
Hiren solanki 5-Jan-11 8:38am    
Thanks Toli for your correction.
Rajesh Anuhya 5-Jan-11 10:58am    
Good Answer
You can make one with a Label and the following code:

C#
Random r = new Random(DateTime.Now.Millisecond);
int number = r.Next(1, 10);

label.text = number.ToString();
 
Share this answer
 
v2
Hope this is for example i did it.
int my_random(int min, int max)
{
  return rand() % (max - min + 1) + min;
}

call with my_random(1, 9).

This will give an idea.
 
Share this answer
 
Comments
CPallini 5-Jan-11 14:18pm    
That's good old C...

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