# How to simulate a random rotating roulette?

**URL:** <https://community.wolfram.com/t/how-to-simulate-a-random-rotating-roulette/316>\
**Category:** Questions\
**Tags:** fun-and-play, software-development, mathematica, interface-construction\
**Created:** [August 2, 2013, 8:36pm UTC](https://community.wolfram.com/t/how-to-simulate-a-random-rotating-roulette/316 "2013-08-02T20:36:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![crystalf](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/crystalf/32/30248_2.png) [@crystalf](https://community.wolfram.com/u/crystalf)\
**Post date:** [August 2, 2013, 8:36pm UTC](https://community.wolfram.com/t/how-to-simulate-a-random-rotating-roulette/316/1 "2013-08-02T20:36:26Z")

</div>

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

```auto
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}
 ]

```

 ![ScreenShot2013-08-02at3.35.50PM.png](https://global.discourse-cdn.com/wolfram/original/3X/9/f/9feff68b38bda5474d43e9bf8bf99711368dea61.png)

---

<div class="post-metadata">

**Author:** ![seokin4862](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@seokin4862](https://community.wolfram.com/u/seokin4862)\
**Post date:** [August 3, 2013, 12:03am UTC](https://community.wolfram.com/t/how-to-simulate-a-random-rotating-roulette/316/2 "2013-08-03T00:03:59Z")

</div>

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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![shenghuiy](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/shenghuiy/32/36073_2.png) [@shenghuiy](https://community.wolfram.com/u/shenghuiy)\
**Post date:** [August 3, 2013, 2:14am UTC](https://community.wolfram.com/t/how-to-simulate-a-random-rotating-roulette/316/3 "2013-08-03T02:14:33Z")

</div>

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](http://reference.wolfram.com/mathematica/ref/Manipulate.html) function which allows the customized control. Here is how you add such a new random number generator into the demo:

```auto
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.

 ![button.PNG](https://global.discourse-cdn.com/wolfram/original/3X/2/0/201085ee22d1411d652504ed0e2eac40cc91cfdc.png)

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

1. [3D Boid Model  
 ](http://demonstrations.wolfram.com/3DBoidModel/)2. [Buttons Manipulate](http://demonstrations.wolfram.com/ButtonsInManipulate/)

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

---

<div class="post-metadata">

**Author:** ![Vitaliyk](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/vitaliyk/32/45591_2.png) [@Vitaliyk](https://community.wolfram.com/u/Vitaliyk)\
**Post date:** [September 2, 2013, 2:20am UTC](https://community.wolfram.com/t/how-to-simulate-a-random-rotating-roulette/316/4 "2013-09-02T02:20:58Z")

</div>

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](http://reference.wolfram.com/mathematica/tutorial/AdvancedManipulateFunctionality.html)** to solve this problem:

```auto
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](https://global.discourse-cdn.com/wolfram/original/3X/9/f/9f98c655f4ddd1793dba51aa1886c95294485b4f.gif)
