# Unit 3 Design A Scene - Opacity as a parameter

**URL:** <https://forum.code.org/t/unit-3-design-a-scene-opacity-as-a-parameter/31908>\
**Category:** Unit and Lesson Discussion\
**Created:** [December 12, 2019, 1:18pm UTC](https://forum.code.org/t/unit-3-design-a-scene-opacity-as-a-parameter/31908 "2019-12-12T13:18:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lpiazza](https://avatars.discourse-cdn.com/v4/letter/l/977dab/32.png) [@lpiazza](https://forum.code.org/u/lpiazza)\
**Post date:** [December 12, 2019, 1:18pm UTC](https://forum.code.org/t/unit-3-design-a-scene-opacity-as-a-parameter/31908/1 "2019-12-12T13:18:46Z")

</div>

My students are trying to send in a parameter for the opacity of the PenRGB command. When they do, the opacity doesn’t change. In some iterations, the snowflake (see below) in the example doesn’t show at all. Is it possible to randomize opacity?

> **[Check out what I made](https://studio.code.org/projects/applab/WqgHWNuRW-VnIcS-_374opN0BB-kKpVJ4Hta05NKlJo)**
>
> I wrote the code myself with Code.org

---

<div class="post-metadata">

**Author:** ![bhatnagars](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/bhatnagars/32/4919_2.png) [@bhatnagars](https://forum.code.org/u/bhatnagars)\
**Post date:** [December 12, 2019, 3:06pm UTC](https://forum.code.org/t/unit-3-design-a-scene-opacity-as-a-parameter/31908/2 "2019-12-12T15:06:02Z")

</div>

randomNumber(0,1) will only toggle between 0 and 1. It does not return any decimal number. In order to get decimal numbers between 0 and 1, try this randomNumber(0,100)/100.0

---

<div class="post-metadata">

**Author:** ![lpiazza](https://avatars.discourse-cdn.com/v4/letter/l/977dab/32.png) [@lpiazza](https://forum.code.org/u/lpiazza)\
**Post date:** [December 12, 2019, 5:56pm UTC](https://forum.code.org/t/unit-3-design-a-scene-opacity-as-a-parameter/31908/3 "2019-12-12T17:56:21Z")

</div>

Thank you, thank you, thank you! This makes perfect sense.

---

<div class="post-metadata">

**Author:** ![infinitestasis](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/infinitestasis/32/5047_2.png) [@infinitestasis](https://forum.code.org/u/infinitestasis)\
**Post date:** [December 12, 2019, 10:29pm UTC](https://forum.code.org/t/unit-3-design-a-scene-opacity-as-a-parameter/31908/4 "2019-12-12T22:29:17Z")

</div>

An even better solution is just to use

```javascript
random() //returns a float between 0 and 1
```

---

<div class="post-metadata">

**Author:** ![frank\_w\_lee](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/frank_w_lee/32/4895_2.png) [@frank\_w\_lee](https://forum.code.org/u/frank_w_lee)\
**Post date:** [December 15, 2019, 5:42am UTC](https://forum.code.org/t/unit-3-design-a-scene-opacity-as-a-parameter/31908/5 "2019-12-15T05:42:20Z")

</div>

Hm, I don’t see that anywhere in the toolbox and I got an error when I tried to use that. I assume you’re referring instead to Math.random(), which seems to match the description you gave.

Also I think it’s great that we promote multiple ways of solving the same problem.

---

<div class="post-metadata">

**Author:** ![infinitestasis](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/infinitestasis/32/5047_2.png) [@infinitestasis](https://forum.code.org/u/infinitestasis)\
**Post date:** [December 15, 2019, 9:16am UTC](https://forum.code.org/t/unit-3-design-a-scene-opacity-as-a-parameter/31908/6 "2019-12-15T09:16:40Z")

</div>

You’re right. random() doesn’t actually exist on app lab. However it does exist on game lab so I guess that’s how I ended up with “random.”
