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
Asked
Active
Viewed 178 times
1
-
Get two random numbers. One from 30000 to 50000 and one from 0 to 1. If the seoond one is zero then subtract and if it is 1 then add. – Jerry Jeremiah Apr 11 '22 at 01:15
3 Answers
1
What about something like this?
if random(0,1) is equal to 1
money += random(30000,50000)
else
money -= random(30000,50000)
There's a 50/50 chance of gaining, or losing, and then it will pick random. Click the checkmark if this helped.

R3FL3CT
- 551
- 3
- 14
1
A MUCH cough cough cleaner method is:
money += (random(0, 1)*2-1)*random(30000, 50000)
All in one block!

Falling10fruit
- 197
- 1
- 12
-
That's fair. But it does become a little less readable, in my opinion. It's just harder to see what the code is doing at a glance. – R3FL3CT Apr 26 '22 at 02:31
-
0
Here's how you could write this in Scratch (For context, I am using the scratchblocks
code format):
[scratchblocks]
when this sprite clicked
if <[(pick random (0) to (1))] = [0]>
change [money v] by (((-1) * ((pick random (30000) to (50000)))
else
change [money v] by ((pick random (30000) to (50000))
end
[\scratchblocks]
This is basically what it would look like in Scratch:
Hope this helps!

CrSb0001
- 151
- 1
- 11