5
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ as per which program by verbeia? Have you looked at RandomSample? Also, what have you tried doing? $\endgroup$
    – rm -rf
    Commented Jul 5, 2012 at 13:49
  • $\begingroup$ @R.M, the one on his previous question, apparently... $\endgroup$ Commented Jul 5, 2012 at 13:53
  • $\begingroup$ 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 $\endgroup$
    – Ajasja
    Commented Jul 5, 2012 at 14:24

1 Answer 1

6
$\begingroup$

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}}
$\endgroup$
3
  • 6
    $\begingroup$ sigh... just when I try to teach a man to fish :/ $\endgroup$
    – rm -rf
    Commented Jul 5, 2012 at 14:01
  • 10
    $\begingroup$ 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. $\endgroup$
    – Mr.Wizard
    Commented Jul 5, 2012 at 14:04
  • $\begingroup$ lol 10987654321 $\endgroup$
    – rm -rf
    Commented Jul 5, 2012 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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