Click here to Skip to main content
15,509,585 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
I have a project with a question and an answer portion. How can I code in random? I need to have a time limit to answer the question. How do I do that? Please help..
Updated 22-Sep-10 22:52pm
T.Saravanann 23-Sep-10 3:24am    
what do you want? Are you try anything?
Your Question is not clear.
Johnny J. 23-Sep-10 3:51am    
This is the third time I have formatted the subject for you. I'll explain again: When you write the subject text IT SHOULD SAY SOMETHING ABOUT WHAT YOUR QUESTION IS ABOUT. Not just "Help Me".

PLUS: Your spelling sucks! Doesn't your keyboard have any "shift" key so you can write capital letters? It's "I" - not "i". And questions are normally terminated by a question mark. If you were to put a little effort into writing your questions, people would be more inclined to answer them...

1 solution

Random r = new Random();
int questionNumber = r.Next(0, numberOfQuestions);
Timer t = new Timer();
t.Interval = 10000;    // 10 seconds
t.Elapsed+=new ElapsedEventHandler(OnTimedEvent);

private static void OnTimedEvent(object source, ElapsedEventArgs e)
   Timer t = source as Timer;
   if (t != null)

There are some details, like keeping the Random object as part of your class to ensure it is different each time, making sure you don't ask teh same question twice in a session, etc. But those you can handle with a bit of thought.
Share this answer

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