mit-scratch

How do I use the Random Function In Scratch for a Gain and a Loss


I want to use a random function for my code. I want the user to be able to click the Bitcoin symbol and lose anywhere from 30,000-50,000 dollars or gain anything from 30,000-50,000 dollars. I do not want to do something where it picks a random from -30,000-50,000. The number range there is too big and the chances of losing money are high. I want to have it be you either gain or you lose this much. How would I go about doing that. Simply put how do I use the random function to gain or lose money without putting such a huge range. My Current Scratch Code


Solution

  • A MUCH cough cough cleaner method is:

    money += (random(0, 1)*2-1)*random(30000, 50000)

    All in one block!