How To Make A Random Generator In Scratch.mit
- Pixbot_Gaming (Caprock64 on Scratch)

- Apr 13, 2022
- 2 min read
What's Scratch? it's a online site with a coding for beginners.
It Uses "blocks" in the code.
Now, how to make a random generator in scratch:
Step 1:
go to scratch.mit.edu
Step 2,
on the left there's a list of blocks, go to the "events" category and find this block:

then simply drag it to the code area.
Step 3,
go to the "variables" category and click "new variable" name it "Random" and click "all sprites."
Step 4,
Uncheck the "random variable" so it doesn't show on screen

Step 5,
Grab a "set variable [my variable] to 0" block and switch the [my variable] to [Random] variable, then click it to the "when sprite clicked" block, then, go to the "operators" category and find the "pick random 1 to 10" block and drag it to the 0 in the "set Random to 0" block. (the number 10 depends on how many things will happen.) After this you should have a piece of code like this:

Step 6,
Now, go to the "control" category and drag the "If <> Then block" then go back to the "operators" category and drag in a code block by this title: "( ) = 50 and place it in the <> part of the "If <> Then" block and set the number to 1 instead of 50 like so:

Step 7,
now go back to the "variables" category and add a "Random" block to the code like this:

then connect the two pieces of code together and copy the code above, and change the number for each of the "If <> then" blocks with code in them, feel free to add your own items in the "If <> then" blocks. and your done!
some things to note:
-you need the same amount of numbers in the "set random 1 to 10" block by changing the 10 for the code to work correctly (unless you amount IS ten because then is works fine)
-make sure to connect the blocks together.


Comments