Discuss Scratch

Natachu
Scratcher
21 posts

How do I make a random number generator, but never have them repeat? Can you show me an example with blocks?

How do I make a random number generator, but never have them repeat? Can you show me an example with blocks? Thank you.
imfh
Scratcher
1000+ posts

How do I make a random number generator, but never have them repeat? Can you show me an example with blocks?

What exactly do you want to use this for? Generally you can create a list with all of the values you want to have and then randomly select and delete items from it.

define Initialize Random
delete all of [random v] ::list
set [r v] to [1] // Add every number from 1
repeat (100) // to 100
add (r) to [random v] // to the random list
change [r v] by (1) // Go to the next number
end

define Get Random
set [r v] to (pick random (1) to (length of [random v] :: list)) // Pick a random item
set [rn v] to (item (r) of [random v] :: list) // Get the random number
delete (r) of [random v] // Delete the item so it doesn't get picked again
imfh
Scratcher
1000+ posts

How do I make a random number generator, but never have them repeat? Can you show me an example with blocks?

Please don't make duplicate posts. It makes things very confusing. If your question doesn't get fully answered, ask for more information and wait for someone to respond.

Duplicate: https://scratch.mit.edu/discuss/topic/373009/

Powered by DjangoBB