I want to get 4 unique random floating point numbers in the range <0;9>. How could I do that. Is it possible to do this with a single function so I don’t need to generate random numbers in a loop?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you need four distinct values then you can do something like this…
Note that if you needed to generate many numbers then a proper shuffle implementation will give better performance than
OrderBy: O(n) rather than O(n log n). If you only need a handful of numbers thenOrderBywill be fine.