Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Random number help.
- TheHockeyist
-
Scratcher
1000+ posts
Random number help.
What I want to do is to pick a random number from 1-100 with a certain probability. For example, numbers closer to 100 will appear much more often than those closer to 1. It will be rare to get a number less than 50 and you usually get a number greater than 80, but it is still possible to get a 1.
Every so often, the number will change slightly. If the number is higher, it will usually go lower, and if the number is lower, it will usually go higher, but again, the new result is usually greater than 80 (the result is usually between 80-100) and rarely less than 50, but still possible to get a 1 if conditions are just right. (It is absolutely impossible to get a 0.)
So at about 87, there is exactly a 50-50 chance of going either higher or lower by a random number. At 50, you will usually go higher almost like a rule, but it is still possible to go lower. At 100, you definitely go lower, and at 1, you definitely go higher.
After a while of changing the number, it is thrown out the door and a brand new number is generated according to the rules of the first paragraph.
Is this possible? I'm sure it is, but how would you go about doing this?
Every so often, the number will change slightly. If the number is higher, it will usually go lower, and if the number is lower, it will usually go higher, but again, the new result is usually greater than 80 (the result is usually between 80-100) and rarely less than 50, but still possible to get a 1 if conditions are just right. (It is absolutely impossible to get a 0.)
So at about 87, there is exactly a 50-50 chance of going either higher or lower by a random number. At 50, you will usually go higher almost like a rule, but it is still possible to go lower. At 100, you definitely go lower, and at 1, you definitely go higher.
After a while of changing the number, it is thrown out the door and a brand new number is generated according to the rules of the first paragraph.
Is this possible? I'm sure it is, but how would you go about doing this?
- stickfiregames
-
Scratcher
1000+ posts
Random number help.
I might try
This would pick a random number from 1 to the number, skewed towards the number:
This whole script should look something like this:
(pick random (pick random (1) to (100)) to (100))
This would pick a random number from 1 to the number, skewed towards the number:
(pick random (pick random (1) to (number)) to (number))and this for a number between the number and 100:
(pick random (number) to (pick random (number) to (100)))
This whole script should look something like this:
foreverI haven't tested it so I don't know the exact chance of getting a specific number, but this should work.
set [number v] to (pick random (pick random (1) to (100)) to (100))
wait until <ready to change number :: grey>
repeat until <ready to throw out number :: grey>
if <(pick random (pick random (1) to (number)) to (number)) < (number)> then
set [number v] to (pick random (pick random (1) to (number)) to (number))
else
set [number v] to (pick random (number) to (pick random (number) to (100)))
end
wait until <ready to change number :: grey>
end
end
Last edited by stickfiregames (Sept. 18, 2014 07:16:46)
- drmcw
-
Scratcher
1000+ posts
Random number help.
I like the vagueness “about 87” then precision of “exactly 50-50” 
The way I would do that would be with a llist and fill it with the numbers with the distribution you want, so you'd need a list and it would have maybe 1000 items in it. The first item would be 1 and the second 2, maybe the third item would also be 2 or possibly 3. You'd have to make it so that at the 500th item would be about 87 and the 1000th would definitely be 100. Do that and you can then use;

The way I would do that would be with a llist and fill it with the numbers with the distribution you want, so you'd need a list and it would have maybe 1000 items in it. The first item would be 1 and the second 2, maybe the third item would also be 2 or possibly 3. You'd have to make it so that at the 500th item would be about 87 and the 1000th would definitely be 100. Do that and you can then use;
set [random number v] to (item (random v) of [distribution v])
Last edited by drmcw (Sept. 18, 2014 09:03:58)
- TheIceHockeyist
-
Scratcher
2 posts
Random number help.
-snip-
Well, the first part of initially generating a random number works very well for me. The “changing script” is failing on me.
- TheHockeyist
-
Scratcher
1000+ posts
Random number help.
-snip-
Well, the first part of initially generating a random number works very well for me. The “changing script” is failing on me.
TheIceHockeyist is my testing account, btw. It's still me.
- TheHockeyist
-
Scratcher
1000+ posts
Random number help.
Well, it seems to work the way I intentionally wanted it to after a bit of experimentation with the pick random block. Closing now.
- Discussion Forums
- » Help with Scripts
-
» Random number help.