Discuss Scratch

Natachu
Scratcher
21 posts

How do I create a number generator (1-75), but never have them repeat? Help me, and you can get a shoutout

I am trying to make a BINGO game, but I dont know how to make a number generator that doesnt repeat.

If you help me, you can get a shout out

(BONUS: how to make the numbers on cards be different every time. Will follow you if you do this!)
deck26
Scratcher
1000+ posts

How do I create a number generator (1-75), but never have them repeat? Help me, and you can get a shoutout

Best way is to create a list of numbers 1 to 75, select a number from 1 to length of list and delete that item after using it.

I assum you mean numbers on bingo cards. Each column covers a range of 10 numbers from memory and there will be at least one number in each column - so alwyas one number from 21 to 30 for example. The remaining numbers up to whatever the count is can be allocated randomly although more than 3 ina column may be sensible.

To ensure no repeats one option would be a list. Join the numbers together - eg 151721 etc and store that in a list. only add new cards if the list doesn't contain that value. You may want to add leading zeroes to single digit values.

Last edited by deck26 (Oct. 17, 2019 16:07:30)

Natachu
Scratcher
21 posts

How do I create a number generator (1-75), but never have them repeat? Help me, and you can get a shoutout

Can you show me a sample of how do do that with the blocks?
imfh
Scratcher
1000+ posts

How do I create a number generator (1-75), but never have them repeat? Help me, and you can get a shoutout

Copied from duplicate: https://scratch.mit.edu/discuss/topic/373012/

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

Powered by DjangoBB