Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

selecting random values from an array based on a condition

807597Jun 8 2005 — edited Jun 9 2005
Hi All,

I have a small glitch here. hope you guys can help me out.

I have an evenly spaced integer array as X[ ] = {1,2,3, ....150}. and I need to create a new array which selects 5 random values from X [ ] , but with a condition that these random values should have a difference of atleast 25 between them.

for example res [ ] = {2,60,37,110,130}
res [ ] = {10,40,109,132,75}

I have been thinking of looping thru the X [ ], and selecting randomly but things look tricky once I sit down to write an algorithm to do it.

Can anyone think of an approach to do this, any help will be greatly appreciated ...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 7 2005
Added on Jun 8 2005
12 comments
452 views