Discuss Scratch

OMYGAWDITSOCUTE
Scratcher
100+ posts

Randomize items in list

The name says it all.
Could be useful in some situations.
when I receive [randomize list v]
randomize items in [list a v] ::list

Last edited by OMYGAWDITSOCUTE (May 28, 2018 21:02:45)

Kano_Llama_Llama
Scratcher
32 posts

Randomize items in list

Try this for picking random songs in a list:
when green flag clicked
delete (all v) of [list a v]
add [song1] to [list a v]
add [song2] to [list a v]
add [song3] to [list a v]
play sound (item (random v) of [list a v] :: list)
if you name all the sounds/songs “song1” “song2” and “song3” then it will play the selected one.

Try this for just picking a random item in said list:
when green flag clicked
delete (all v) of [list b v]
add [random1] to [list b v]
add [random2] to [list b v]
add [random3] to [list b v]
set [Random item v] to (item (random v) of [list b v] :: list)

Last edited by Kano_Llama_Llama (May 28, 2018 23:55:06)

ACE009
Scratcher
100+ posts

Randomize items in list

If you want to have the whole list randomized for later, you can use the script below:
set [counter v] to (0)
repeat (length of [list v] :: list)
change [counter v] by (1)
insert (item (counter) of [list v] :: list) at (pick random (1) to (counter)) of [list v]
delete ((counter) + (1)) of [list v]
end
This works by placing each item in the list in a random position relative to the rest of the previously randomized items. Example of a single repeat stage: items 1, 2, and 3 of a five element list have been randomized; item 4 is then moved at one of the following positions: before 1, after 1 and before 2, after 2 and before 3, or after 3.

Last edited by ACE009 (May 29, 2018 00:47:51)

OMYGAWDITSOCUTE
Scratcher
100+ posts

Randomize items in list

ACE009 wrote:

If you want to have the whole list randomized for later, you can use the script below:
set [counter v] to (0)
repeat (length of [list v] :: list)
change [counter v] by (1)
insert (item (counter) of [list v] :: list) at (pick random (1) to (counter)) of [list v]
delete ((counter) + (1)) of [list v]
end
Ooh neat.
GullumIncComicz
Scratcher
100+ posts

Randomize items in list

repeat (10)
add (pick random (1) to (10)) to [list v]
end

Now there are random numbers in the list.
-ShadowOfTheFuture-
Scratcher
1000+ posts

Randomize items in list

GullumIncComicz wrote:

repeat (10)
add (pick random (1) to (10)) to [list v]
end

Now there are random numbers in the list.

The suggestion is to be able to take an existing list and randomize the order of the items in it.

Curse you, 60-second rule…
ACE009
Scratcher
100+ posts

Randomize items in list

-ShadowOfTheFuture- wrote:

GullumIncComicz wrote:

repeat (10)
add (pick random (1) to (10)) to [list v]
end

Now there are random numbers in the list.

The suggestion is to be able to take an existing list and randomize the order of the items in it.

Curse you, 60-second rule…
Which my workaround does with only one extra variable. Anyway, if you were to use hacked blocks, you can have a custom block take a list dropdown input and then put the var for that in the list blocks.
GoldenSpudCode
Scratcher
1 post

Randomize items in list

ACE009 wrote:

If you want to have the whole list randomized for later, you can use the script below:
set [counter v] to (0)
repeat (length of [list v] :: list)
change [counter v] by (1)
insert (item (counter) of [list v] :: list) at (pick random (1) to (counter)) of [list v]
delete ((counter) + (1)) of [list v]
end
This works by placing each item in the list in a random position relative to the rest of the previously randomized items. Example of a single repeat stage: items 1, 2, and 3 of a five element list have been randomized; item 4 is then moved at one of the following positions: before 1, after 1 and before 2, after 2 and before 3, or after 3.

Thanks so much, this makes card games so much easier!

Powered by DjangoBB