Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » help with RNG
- br0dy161212
-
Scratcher
31 posts
help with RNG
ok so i know how to make RNG but when i implent it into my game its often happening that i get the same thing in a row but i dont want that can somebody help me with this? btw heres how i make my RNG if it helps:
set RNG to: pick random 1 to 4
if RNG=1: do …
if RNG=2: do …
if RNG=3: do …
if RNG=4: do …
set RNG to: pick random 1 to 4
if RNG=1: do …
if RNG=2: do …
if RNG=3: do …
if RNG=4: do …
- RokCoder
-
Scratcher
1000+ posts
help with RNG
If you want to ensure you never get the same number twice in a row you can force that outcome in a number of ways. Here's an example -
An alternative method would be -
when flag clicked
set [_rng v] to (pick random (1) to (4)) // Initialise the variable
define _rng = pick different random value // Call this to get a different number
set [_rng v] to ((((_rng) + (pick random (0) to (2))) mod (4)) + (1))
An alternative method would be -
define _rng = pick different random value // This should be a non-refresh custom block
set [_oldVal v] to (_rng)
repeat until <not <(_rng) = (_oldVal)>>
set [_rng v] to (pick random (1) to (4))
Last edited by RokCoder (April 3, 2025 08:14:52)
- br0dy161212
-
Scratcher
31 posts
help with RNG
If you want to ensure you never get the same number twice in a row you can force that outcome in a number of ways. Here's an example -when flag clicked
set [_rng v] to (pick random (1) to (4)) // Initialise the variable
define _rng = pick different random value // Call this to get a different number
set [_rng v] to ((((_rng) + (pick random (0) to (2))) mod (4)) + (1))
An alternative method would be -define _rng = pick different random value // This should be a non-refresh custom block
set [_oldVal v] to (_rng)
repeat until <not <(_rng) = (_oldVal)>>
set [_rng v] to (pick random (1) to (4))
thx but what do i need to do with that block i made?
cuz it ofc doesnt do anything rn cuz idk where to put it
- RokCoder
-
Scratcher
1000+ posts
help with RNG
thx but what do i need to do with that block i made?Call it from wherever you were previously creating a random number.
cuz it ofc doesnt do anything rn cuz idk where to put it
set [_rng v] to (pick random (1) to (4)
if <(_rng) = (1)> then
else
if <(_rng) = (2)> then
else
if <(_rng) = (3)> then
else
Becomes -
_rng = pick different random value :: custom
if <(_rng) = (1)> then
else
if <(_rng) = (2)> then
else
if <(_rng) = (3)> then
else
- br0dy161212
-
Scratcher
31 posts
help with RNG
thx but what do i need to do with that block i made?Call it from wherever you were previously creating a random number.
cuz it ofc doesnt do anything rn cuz idk where to put itset [_rng v] to (pick random (1) to (4)
if <(_rng) = (1)> then
else
if <(_rng) = (2)> then
else
if <(_rng) = (3)> then
else
Becomes -_rng = pick different random value :: custom
if <(_rng) = (1)> then
else
if <(_rng) = (2)> then
else
if <(_rng) = (3)> then
else
ty
- Discussion Forums
- » Help with Scripts
-
» help with RNG