I would not check that the number is < 20; I would do something different
Agree. Most computing problems have many good solutions (and even more bad solutions).
Panagiotis Kalogeropoulos wrote: . . . there are many ways to solve this, . . .
Abhijit Ajansondkar wrote:Thanks Panagiotis Kalogeropoulos !
This is my code but it is producing the numbers < 20 but the number of elements and uniqueness are not guaranteed.There is repitition .[code=java]
Abhijit Ajansondkar wrote:actually the constraint is the getRand() method . so you have don't have any other option except this method which produces a random integer between 1 to 100.
so please help me !
Campbell Ritchie wrote:Good grief! I never noticed you are creating a new random object every time you call that getRand method. You should’t do that.
Actually, the other problem of how to produce 200 distinct random values from an engine that only produces 100 is kind of fun - and not as obvious as you might think. Took me this morning's coffee to work it out.
Panagiotis Kalogeropoulos wrote:At first glance it seems intriguing, but actually it is not.
If you post code that I notice subtle errors in, I shall made d*mn sure to leave it. Mwaahaahaahaahaahaa!!
Panagiotis Kalogeropoulos wrote: . . . (so that we will not be accused of giving easy and painless code.... ).
Yes, that is what they say after the copy and hand it in, and only later find the subtle errors!
Panagiotis Kalogeropoulos wrote:
Campbell Ritchie wrote:Yes, that is what they say after the[y] copy and hand it in, and only later find the subtle errors!