Click here to Skip to main content
15,949,741 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
Posted

1 solution

This is about System.Random, see http://msdn.microsoft.com/en-us/library/system.random.aspx[^]. 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.

—SA
 
Share this answer
 
Comments
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?
--SA

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