selecting random values from an array based on a condition
807597Jun 8 2005 — edited Jun 9 2005Hi 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 ...