Click here to Skip to main content
15,881,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
plz help me in generating 5 unique random number between 0 to 8

1 solution

This is about System.Random, see[^]. Don't repeat a common mistake, the instance of this class only once (per application domain per runtime).

What means "unique"? Does it mean all 5 should be different? In this case, put all generated values in dictionary (System.Collection.Generic.Dictionary); each time check up if the newly added value is already in dictionary. If it is already there, try again, if not add it.

Share this answer
junisarfraz 14-Jul-11 1:31am    
unique means different
Sergey Alexandrovich Kryukov 19-Jul-11 17:37pm    
Thank you for your confirmation. So, my recommendation to use Dictionary will work in this case. This is the solution.
Is anything still unclear?

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