# randomSwitch with 0 percent probability

**URL:** <https://community.gatling.io/t/randomswitch-with-0-percent-probability/1955>\
**Category:** Gatling (Open-Source)\
**Created:** [January 31, 2015, 12:58am UTC](https://community.gatling.io/t/randomswitch-with-0-percent-probability/1955 "2015-01-31T00:58:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Bo](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@Brian\_Bo](https://community.gatling.io/u/Brian_Bo)\
**Post date:** [January 31, 2015, 12:58am UTC](https://community.gatling.io/t/randomswitch-with-0-percent-probability/1955/1 "2015-01-31T00:58:07Z")

</div>

Hi,

I found that if the **first** case in a randomSwitch has 0% probability and the other cases don’t make any http calls, the first chain will still get executed even with 0% probability.  
For example,

randomSwitch(  
0d → exec(http(“YouTube”).get(“[http://www.youtube.com/](http://www.youtube.com/)”)),  
50d → doIf(“1”, “2”) {  
exec(http(“Google”).get(“[http://www.google.ca](http://www.google.ca)”))  
},  
50d → exec()  
)

Requests to YouTube is made.  
Is that expected? Is 0% not allowed?

Thanks,  
Brian

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [January 31, 2015, 8:55am UTC](https://community.gatling.io/t/randomswitch-with-0-percent-probability/1955/2 "2015-01-31T08:55:41Z")

</div>

Can’t reproduce.  
Then, please abide to the rules for posting here: [https://groups.google.com/forum/#!forum/gatling](https://groups.google.com/forum/#!forum/gatling)

---

<div class="post-metadata">

**Author:** ![Brian\_Bo](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@Brian\_Bo](https://community.gatling.io/u/Brian_Bo)\
**Post date:** [February 3, 2015, 6:58pm UTC](https://community.gatling.io/t/randomswitch-with-0-percent-probability/1955/3 "2015-02-03T18:58:58Z")

</div>

Sorry for not following the rules. I have checked the documentation and I don’t see anyone ask a similar question.

I’m running **2.1.4** , on a Windows 7 64 bit machine.

I have attached my simulation file, which it does only the random switch I posted above.

Again, requests to Youtube is made, even it has 0% probability in a random switch.

Thanks,  
Brian

[TestSim.scala](https://community.gatling.io/uploads/short-url/312J44A5tXoffGBHOa2XSvipvVw.scala) (444 Bytes)

---

<div class="post-metadata">

**Author:** ![Abhinav\_Gogna](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Abhinav\_Gogna](https://community.gatling.io/u/Abhinav_Gogna)\
**Post date:** [February 3, 2015, 7:55pm UTC](https://community.gatling.io/t/randomswitch-with-0-percent-probability/1955/4 "2015-02-03T19:55:04Z")

</div>

Code:

`randomSwitch( 0.00 -> exec(http("YouTube").get("http://www.youtube.com/")), 50.00 -> exec(http("Google").get("http://www.google.ca")), 50.00 -> exec(http("Github").get("https://github.com/")) )Enter code here...`

Result:

[![](https://lh4.googleusercontent.com/-dt_H3aHdwPg/VNEnR6cvdZI/AAAAAAAAA-A/gxG7103H0y4/s400/random_switch.png)](https://lh4.googleusercontent.com/-dt_H3aHdwPg/VNEnR6cvdZI/AAAAAAAAA-A/gxG7103H0y4/s1600/random_switch.png)

---

<div class="post-metadata">

**Author:** ![Brian\_Bo](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@Brian\_Bo](https://community.gatling.io/u/Brian_Bo)\
**Post date:** [February 3, 2015, 8:16pm UTC](https://community.gatling.io/t/randomswitch-with-0-percent-probability/1955/5 "2015-02-03T20:16:01Z")

</div>

This is fine, given that the 2nd and 3rd cases actually make http requests.

However, if the 2nd and 3rd make no http requests (like in my original example), the request with 0% probability is made.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [February 3, 2015, 8:54pm UTC](https://community.gatling.io/t/randomswitch-with-0-percent-probability/1955/6 "2015-02-03T20:54:59Z")

</div>

Fixed thanks: [https://github.com/gatling/gatling/issues/2544](https://github.com/gatling/gatling/issues/2544)
