Discuss Scratch

44stuffyconvention
Scratcher
99 posts

Random 2-digit number list generator no repeats?

So, I have a list that I want to have 20 items: each item being a random 2-digit number. I want the list to have no repeats

My idea and some of my code:

when green flag clicked
repeat (20)
add (pick random (10) to (99)) to [resualt v]
end
repeat until <list has no more duplicates>
find duplicates
replaces duplicates with other random numbers
end

is there any way to make this works

Last edited by 44stuffyconvention (Sept. 29, 2022 04:46:57)

Oumuamua
Scratcher
1000+ posts

Random 2-digit number list generator no repeats?

deck26
Scratcher
1000+ posts

Random 2-digit number list generator no repeats?

Easy enough

delete [all v] of [mylist v]
set [myrand v] to (pick random (10) to (99))
add (myrand) to [mylist v]
repeat [19]
repeat until <not <[mylist v] contains (myrand) ?>>
set [myrand v] to (pick random (10) to (99))
end
add (myrand) to [mylist v]
end
Redclopez
Scratcher
19 posts

Random 2-digit number list generator no repeats?

faster way for this to work:
when flag clicked
delete all of [result v] :: lists
repeat until <(length of [result v])=(20)>
set [random num v] to (pick random (10) to (99))
if <not<list contains (random num)>> then
add (random num) to [result v]

Powered by DjangoBB