Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Using seeds for randomly generated games and roguelikes
- FalconGunner99
-
Scratcher
1000+ posts
Using seeds for randomly generated games and roguelikes
So I've been playing a lot of binding of isaac lately and that got me thinking. With random seeds, you can give players a much more communal experience, one that allows people to share their experience through more than just recording it and slapping it on youtube. and then that got me thinking, how does one accomplish this on scratch?
In a regular programming language, all a seed is is a number for an RNG to grow off of, producing a bigger and bigger number with every variation (See this video https://www.youtube.com/watch?v=Ac4Z1VMsE3E ) Normally computers get their seed from the time in milliseconds, but if you specify that seed, you can generate the same numbers every time. With scratch though, we don't have that close of an involvement with the RNG, you can only ask for a random number, 1 to 0, and it will give you one, presumably always based on a random seed, like the time. So I'm thinking the only way around this is to write your own script for an RNG, and use variables instead of (pick random 0 to 9) blocks.
So what do you think is the best way to approach it?
How can we use it in games that are made on scratch, where we can't specify seeds as easily?
In a regular programming language, all a seed is is a number for an RNG to grow off of, producing a bigger and bigger number with every variation (See this video https://www.youtube.com/watch?v=Ac4Z1VMsE3E ) Normally computers get their seed from the time in milliseconds, but if you specify that seed, you can generate the same numbers every time. With scratch though, we don't have that close of an involvement with the RNG, you can only ask for a random number, 1 to 0, and it will give you one, presumably always based on a random seed, like the time. So I'm thinking the only way around this is to write your own script for an RNG, and use variables instead of (pick random 0 to 9) blocks.
So what do you think is the best way to approach it?
How can we use it in games that are made on scratch, where we can't specify seeds as easily?
- gtoal
-
Scratcher
1000+ posts
Using seeds for randomly generated games and roguelikes
How can we use it in games that are made on scratch, where we can't specify seeds as easily?
Create a cloud var and initialise it by hand to an invalid seed (eg -1). Then have the program test to see if it is not set, and if not, set it to something like random 0 to whatever. That should only happen once, and then everyone will see the same seed.
G
- liam48D
-
Scratcher
1000+ posts
Using seeds for randomly generated games and roguelikes
With scratch though, we don't have that close of an involvement with the RNG, you can only ask for a random number, 1 to 0, and it will give you one, presumably always based on a random seed, like the time.
((pick random (0) to (100000)) / (100000)
Gives you any number from 0 to 1 with an accuracy of 5 decimal digits.

- MegaApuTurkUltra
-
Scratcher
1000+ posts
Using seeds for randomly generated games and roguelikes
With scratch though, we don't have that close of an involvement with the RNG, you can only ask for a random number, 1 to 0, and it will give you one, presumably always based on a random seed, like the time.((pick random (0) to (100000)) / (100000)
Gives you any number from 0 to 1 with an accuracy of 5 decimal digits.
(pick random (0.0) to (1.0)You're missing the point though. What OP wants is a seed-based PRNG that will generate the same sequence of random numbers for any given seed. It's like how minecraft worlds always generate the same way for the same seed; minecraft uses a seed-based PRNG
Last edited by MegaApuTurkUltra (April 1, 2015 12:38:27)
- FalconGunner99
-
Scratcher
1000+ posts
Using seeds for randomly generated games and roguelikes
See, I can figure out how to do a seed based RNG custom block pretty easy, I'm just wondering how to use that in an actual game for things.
Perhaps something like this for a random item?
This doesn't actually generate numbers on the fly, but if you just have a seed generated at the start put into a list, it could work for having the same game over and over again.
I'm not entirely sure how you'd use an actual seed based RNG anyways so I feel like for simplicity's sake just using a seed like this would work for most games. Although if a user knew enough about the seed they could predetermine their run.
You could make it a bit harder by just adding more math
Bad example because I'm an idiot, but still you see the point
Perhaps something like this for a random item?
when I receive [Item v]
set [ Item v] to (item ( 3 v) of [ Seed v])
This doesn't actually generate numbers on the fly, but if you just have a seed generated at the start put into a list, it could work for having the same game over and over again.
I'm not entirely sure how you'd use an actual seed based RNG anyways so I feel like for simplicity's sake just using a seed like this would work for most games. Although if a user knew enough about the seed they could predetermine their run.
You could make it a bit harder by just adding more math
when I receive [Item v]
set [Item v] to (item ([sqrt v] of ((81) / (9))) of [ Seed v])
Bad example because I'm an idiot, but still you see the point
Last edited by FalconGunner99 (April 1, 2015 18:33:11)
- datab
-
Scratcher
20 posts
Using seeds for randomly generated games and roguelikes
Hi @FalconGunner99,
I've just been wrestling with pseudo random dungeon generation from a seed… Just so I can generate a dungeon level, store the seed, then re-generate if the player comes back to that level
https://scratch.mit.edu/projects/55703948/
I borrowed a “Pseudo random number generator from seed” scripts from @Nintendoge_ https://scratch.mit.edu/projects/43912060/
Cheers, Datab
I've just been wrestling with pseudo random dungeon generation from a seed… Just so I can generate a dungeon level, store the seed, then re-generate if the player comes back to that level
https://scratch.mit.edu/projects/55703948/
I borrowed a “Pseudo random number generator from seed” scripts from @Nintendoge_ https://scratch.mit.edu/projects/43912060/
Cheers, Datab
- FalconGunner99
-
Scratcher
1000+ posts
Using seeds for randomly generated games and roguelikes
Hi @FalconGunner99,Very cool stuff there, and that RNG will be very useful, definitely going in my backpack. The dungeon gen is very cool as well.
I've just been wrestling with pseudo random dungeon generation from a seed… Just so I can generate a dungeon level, store the seed, then re-generate if the player comes back to that level![]()
https://scratch.mit.edu/projects/55703948/
I borrowed a “Pseudo random number generator from seed” scripts from @Nintendoge_ https://scratch.mit.edu/projects/43912060/
Cheers, Datab
Now the question is, how easy is it to actually plug those numbers into a game in a meaningful way, like BOI, Nuclear Throne, and other rogue likes do?
- Discussion Forums
- » Advanced Topics
-
» Using seeds for randomly generated games and roguelikes





