5

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?

Daniel
  • 319
  • 6
  • 12

1 Answers1

6

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}}
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371