1
$\begingroup$

I have a dynamic PopupMenu defined as follow:

var = { PopupMenu[Dynamic[r3], 
   {"",{py,px,tn},{px,py,tn},{-px,-py,tn},{px,py,-tn}}
]}

px,px,tnare 3 numbers.

How can I random sort the order of the these elements, keeping the first always ""?

For example, I would like var to contain

{"",{py,px,tn},{px,py,tn},{-px,-py,tn},{px,py,-tn}}

one time, and another time

{"",{px,py,tn},{py,px,tn},{px,py,-tn},{-px,-py,tn}}

Furthermore, I would like the elements of the PopupMenu displayed in the following form: px,py,tn and not {px,py,tn}

$\endgroup$
  • $\begingroup$ Look up RandomSample[]. $\endgroup$ – J. M. will be back soon May 29 '17 at 12:07
  • $\begingroup$ @Kuba I want to call it in different part of the notebook and "always" have a different result $\endgroup$ – Ale1794 May 29 '17 at 12:14
  • $\begingroup$ Like: var := {PopupMenu[ Dynamic[r3], {"", Sequence @@ RandomSample[{{py, px, tn}, {px, py, tn}, {-px, -py, tn}, {px, py, -tn}}]}]}? $\endgroup$ – Kuba May 29 '17 at 12:16
  • $\begingroup$ Let us continue this discussion in chat. $\endgroup$ – Kuba May 29 '17 at 13:05
2
$\begingroup$
var := PopupMenu[Dynamic[x],
  Prepend[
       # -> Row[#, ","] & /@ RandomSample[
           {{py, px, tn}, {px, py, tn}, {-px, -py, tn}, {px, py, -tn}} 
       ]
    ,  ""
  ]
]

enter image description here

The code should be self explanatory but feel free to ask if anything is unclear.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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