# Reversing Random Distribution

**URL:** <https://discourse.processing.org/t/reversing-random-distribution/17427>\
**Category:** Coding Questions\
**Created:** [January 29, 2020, 7:22pm UTC](https://discourse.processing.org/t/reversing-random-distribution/17427 "2020-01-29T19:22:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PhilRandom](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@PhilRandom](https://discourse.processing.org/u/PhilRandom)\
**Post date:** [January 29, 2020, 7:22pm UTC](https://discourse.processing.org/t/reversing-random-distribution/17427/1 "2020-01-29T19:22:27Z")

</div>

Hello Fellow Coders,  
Phil Again,  
It seems that I have run into another coding predicament…oops.  
I have successfully coded a random distribution descending code that changes color when reaching the bottom of the canvas!  
Needless to say, I have been bitten by the coding bug (no pun intended).  
I was wondering as to how I could reverse this code and have it ascend once it reaches the bottom?  
Thank you!  
Best,  
Phil

---

<div class="post-metadata">

**Author:** ![trikaphundo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/trikaphundo/32/7913_2.png) [@trikaphundo](https://discourse.processing.org/u/trikaphundo)\
**Post date:** [January 29, 2020, 8:47pm UTC](https://discourse.processing.org/t/reversing-random-distribution/17427/2 "2020-01-29T20:47:58Z")

</div>

Hello Phil, first of all, as you are talking about a bug in your code and asking for advice on tuning it to change its behaviour; it would be easier to answer your question if you published a snippet of your code.

Besides that, I am not sure I understood this

> [@PhilRandom](#):
>
> I have successfully coded a random distribution descending code that changes color when reaching the bottom of the canvas!

Do you mean you assign colour to pixels according to a function F(y), where y is the pixel’s height? If so, a simple change of variable will do: G(y) = F(height - y). According to what you said:

> [@PhilRandom](#):
>
> I was wondering as to how I could reverse this code and have it ascend once it reaches the bottom?

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [February 20, 2020, 7:20pm UTC](https://discourse.processing.org/t/reversing-random-distribution/17427/3 "2020-02-20T19:20:04Z")

</div>

@PhilRandom – I hope that you were able to resolve your issue.

If you are trying to reverse a process that descends so that it ascends, you may be interested in this recent discussion – and in looking at the examples of bouncing balls.

> [@Variable must change from 3.67 to 3.15](https://discourse.processing.org/t/variable-must-change-from-3-67-to-3-15/17929):
>
> Hi there! I need my variable i to go from 3.67 to 3.15 to 3.67 to 3.15 to 3.67 and so on. I’m able to do this just fine from 3.67 to 3.15, however I can’t manage to let it go back to 3.67. This is the code i’m using right now: if (i \> 3.16) { i = i / 1.001 } if(i \> 3.67) { i = i \* 1.001 } I understand why it’s not working, but I dont know how to fix it. confused pls help
