Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I assigned energy values to each element in the array as per the program of Verbeia. The program looks like this

Xarray = A @@@ Tuples[Range[0, 1], 3];

energies = 
  RandomVariate[ExponentialDistribution[1.5], {Length@Xarray}];

f = {#, First@Pick[energies, Xarray, #]} &;

f@Xarray[[5]]

Now I want to randomly select let say 5 elements from this 1000 element array such that no element should repeat. Let { 89,5,79,34,900} be the set of elements I've randomly selected. Now for each element I should get the energies and coordinates automatically. Could anyone do this?

share|improve this question
    
as per which program by verbeia? Have you looked at RandomSample? Also, what have you tried doing? –  rm -rf Jul 5 '12 at 13:49
    
@R.M, the one on his previous question, apparently... –  J. M. Jul 5 '12 at 13:53
    
Also, it's good form if you actually accept the answer that has helped you. So far you've asked 3 questions, accepted none and upvoted none. Time to read another faq I'm afraid: mathematica.stackexchange.com/faq#howtoask –  Ajasja Jul 5 '12 at 14:24
    
Thank you Ajasja. I actually don't know to how to accept an answer. –  Daniel Jul 5 '12 at 14:54
add comment

1 Answer

up vote 4 down vote accepted

Use RandomSample:

f /@ RandomSample[Xarray, 5]
{{A[1, 1, 0], 0.666428},
 {A[1, 0, 0], 1.26861},
 {A[0, 0, 0], 0.643917},
 {A[0, 1, 0], 0.114058},
 {A[0, 0, 1], 0.200398}}
share|improve this answer
3  
sigh... just when I try to teach a man to fish :/ –  rm -rf Jul 5 '12 at 14:01
5  
If you light a man a fire you keep him warm for a day. If you light a man on fire you keep him warm for the rest of his life. –  Mr.Wizard Jul 5 '12 at 14:04
    
lol 10987654321 –  rm -rf Jul 5 '12 at 14:06
    
Thank you Mr.Wizard –  Daniel Jul 5 '12 at 14:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.