Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Random Number Generator
- SimplyVector
-
Scratcher
4 posts
Random Number Generator
Hello!
For my new game, I'm trying to make a non-repeating random number generator.
I already developed it, but for some reason, which I don't know, it won't work.
Because of this, I'd like to ask, if you could tell me why it isn't working and help me on fixing it?
I'll give you credit of course!
Here's my script:
Thank you for your help!
For my new game, I'm trying to make a non-repeating random number generator.
I already developed it, but for some reason, which I don't know, it won't work.
Because of this, I'd like to ask, if you could tell me why it isn't working and help me on fixing it?
I'll give you credit of course!
Here's my script:
when green flag clicked
set [NewNumber v] to [1]
forever
broadcast [generateNumber v]
wait (1) secs
end
when I receive [generateNumber v]
set [OldNumber v] to (NewNumber)
delete (all v) of [random v]
add [1] to [random v]
add [2] to [random v]
add [3] to [random v]
add [4] to [random v]
add [5] to [random v]
add [6] to [random v]
delete (OldNumber) of [random v]
set [NewNumber v] to (pick random (item (1 v) of [random v] :: list) to (item (5 v) of [random v] :: list))
Thank you for your help!
- deck26
-
Scratcher
1000+ posts
Random Number Generator
Set up your list and then
set [myrandom v] to ( pick random [1] to (length of [mylist v] :: list)
set [mynumber v] to (item (myrandom) of [mylist v] :: list)
delete (myrandom) of [mylist v]
- SimplyVector
-
Scratcher
4 posts
Random Number Generator
Set up your list and thenset [myrandom v] to ( pick random [1] to (length of [mylist v] :: list)
set [mynumber v] to (item (myrandom) of [mylist v] :: list)
delete (myrandom) of [mylist v]
What the…?!
Okay, I'm confused now.
If I make these blocks before your script (you said to set up my list)
delete (all v) of [mylist v]it'll never work because of that delete all block.
add [1] to [mylist v]
add [2] to [mylist v]
add [3] to [mylist v]
add [4] to [mylist v]
add [5] to [mylist v]
add [6] to [mylist v]
However, if I delete that delete All block, it adds 20 (20!) Items to the list each time the script is activated!
Could you please show me the full script because I am really confused right now.
Thank you.
- deck26
-
Scratcher
1000+ posts
Random Number Generator
You only need to set up the list once before you start selecting items. If you're going to select several random items without repetition you don't set the list up again each time before you choose - that's the whole point, you choose and delete the item so next time it's not there.
So the setting up of the list is done in a separate script before you start any selections and once you start selection you do not reset the list, only delete the item just selected.
So the setting up of the list is done in a separate script before you start any selections and once you start selection you do not reset the list, only delete the item just selected.
- imfh
-
Scratcher
1000+ posts
Random Number Generator
To visualize:
when I receive [Reset random v]
delete (all v) of [mylist v] // Copied from your post, setup list
add [1] to [mylist v]
add [2] to [mylist v]
add [3] to [mylist v]
add [4] to [mylist v]
add [5] to [mylist v]
add [6] to [mylist v]
when I receive [Get random v]
... // Do what @deck 26 showed
- agalati
-
Scratcher
59 posts
Random Number Generator
Hmmmmmmmmmmmm does this work?
when green flag clicked
broadcast [ Random]
when I receive [ Random]
repeat ( 100 or 10 or 1)
play sound [ Number Set]
wait ( 10) secs
add [ Number Set] to [ Number List]
- Wyan100
-
Scratcher
1000+ posts
Random Number Generator
I'm not entirely sure what you want, but I think you would just simply do something like this:
repeat until <not <[NumberList v] contains (Number) ?>>
set [Number v] to (pick random (1) to (100)) //100 can be replaced with any number
end
add (Number) to [NumberList v]
- Pufferfish_Test
-
Scratcher
500+ posts
Random Number Generator
It's great you want to help, but this post is over one year old and has already been answered. Please don't necropost, it clutters up the forums with space that could be used for people who still need help.
Edit: quoting is broken
Last edited by Pufferfish_Test (Aug. 29, 2020 18:12:00)
- Wyan100
-
Scratcher
1000+ posts
Random Number Generator
It's great you want to help, but this post is over one year old and has already been answered. Please don't necropost, it clutters up the forums with space that could be used for people who still need help.
Edit: quoting is broken
Oh I didn't realize that this was an Old Post, @agalati had bumped it back to the top

- TimelessDestruction
-
Scratcher
2 posts
Random Number Generator
How about,
when i receive (broacastname)
set randomnumber to pick random 1 - 100 (100 is optional)
say randomnumber
when i receive (broacastname)
set randomnumber to pick random 1 - 100 (100 is optional)
say randomnumber
- bluedragon8633
-
Scratcher
1000+ posts
Random Number Generator
Not relevant, but should there be a way where older posts don't show up on the front page without being stickied? Sorry for necroposting, just pointing out that not everyone pays attention to the dates, and it's kinda misleading when it shows up alongside all the recent stuff.
- ChanMan871871
-
Scratcher
28 posts
Random Number Generator
when [ somthing] key pressed
(pick random (something) to (something))
broadcast [genaraded number]
- Discussion Forums
- » Help with Scripts
-
» Random Number Generator








