How to simulate a random rotating roulette?

This roulette is pretty simple to construct, but unfortunately it always stops at the same spot. What kind of approaches could we have here?

img = Import["http://goo.gl/0hn0t4"];

Animate[
 Graphics[{
   Rotate[Inset[img, Automatic, Automatic, 2], rot],
   Thickness[.02], Red, 
   Arrow[{{0, 0}, .8 {Sin[7 Pi/33], Cos[7 Pi/33]}}]
   }, PlotRange -> 1, ImageSize -> 300],
 {{rot, 0, "SPIN"}, 0, RandomReal[{0, 4 Pi}], 
  AppearanceElements -> "ResetPlayButton", AnimationRepetitions -> 1, 
  AnimationRunning -> False, DisplayAllSteps -> True}
 ]

I am very inexperienced, and I am sure a better answer will come up.

The problem seems to be that the RandomReal becomes a fixed value when the code is evaluated.

I tried putting dynamic around the RandomReal.

img = Import["http://goo.gl/0hn0t4"];

Animate[Graphics[{Rotate[Inset[img, Automatic, Automatic, 2], rot], 
   Thickness[.02], Red, 
   Arrow[{{0, 0}, .8 {Sin[7 Pi/33], Cos[7 Pi/33]}}]}, PlotRange -> 1, 
  ImageSize -> 300], {{rot, 0, "SPIN"}, 0, 
  Dynamic[RandomReal[{0, 4 Pi}]], 
  AppearanceElements -> "ResetPlayButton", AnimationRepetitions -> 1, 
  AnimationRunning -> False, DisplayAllSteps -> True}]

The roulette stops at a random location, but spins oddly.

I am sure someone else have a better solution.

Hey Crystal,

I can see that your question is about why the RandomReal does not create a new random number as you click the “PlayResetButton”. This behaviour is as designed so you can always replay the same thing again and again. If you want to show a different process, you just need to add control to your function that force the animation to take a new numbe.

The easiest way to do this is via Manipulate function which allows the customized control. Here is how you add such a new random number generator into the demo:

img = Import["http://goo.gl/0hn0t4"];
c = 1;
Manipulate[
 Graphics[{Rotate[Inset[img, Automatic, Automatic, 2], c*rot], 
   Thickness[.02], Red, 
   Arrow[{{0, 0}, .8 {Sin[7 Pi/33], Cos[7 Pi/33]}}]}, PlotRange -> 1, 
  ImageSize -> 300], {{rot, 0, "SPIN"}, 0, 4 \[Pi], 
  ControlType -> Trigger},
 Button["random", c = RandomReal[{0, 1}]]
 ]

After you run this code you can rotate the roulette and stop after 2 turns. Then you can click the “random” button and spin again to stop at a new spot.

If you have question about the code, you may find following two demo helpful:

  1. 3D Boid Model
    2. Buttons Manipulate

Have fun and you can simulate how to get a free ice cream from Cold Stone by doing the roulette experiment now!

I think this application need to satisfy criteria:

  1. All spins must be properly random
  2. Rotation must be visibly smooth and continuous
  3. There should be only a single control “SPIN”
  4. Every time you spin the wheel it needs to start from the point it stopped the previous time

I think we could use the concept of self-triggered Dynamic or automatic reevaluation to solve this problem:

img = Import["http://goo.gl/ehiHI0"];

Manipulate[
 y = Min[up, y + .02];
 Graphics[Inset[img, Automatic, Automatic, 2, {Cos[2 Pi y], Sin[2 Pi y]}], PlotRange -> 1, ImageSize -> 250],
 Button["SPIN", up = RandomReal[]; y = y - 1],
 {up, 1, ControlType -> None},
 {{y, 1}, -2, 1, ControlType -> None}]

2421spin.gif