Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Shuffling Lists
- Mick456
-
11 posts
Shuffling Lists
How do you make it so that the program shuffles a list without repeating any existing values (e.g. You becomes Yuu)?
- dimitrip
-
500+ posts
Shuffling Lists
Hi.
Here a simple (and less performant) one.
Dimitri
Here a simple (and less performant) one.
delete [all v] of [liste2 v]Cheers.
repeat until < ( length of [liste1 v] :: list) < [1] >
set ( i) to (pick random (1) to (length of [liste1 v]))
add (item (i) of [liste1 v]) to [liste2 v]
delete ( i) of [liste1 v]
end
Dimitri
- dimitrip
-
500+ posts
Shuffling Lists
Hi again.
This one seems more efficient.
See also more info on bias, here.
Greetz.
Dimitri
This one seems more efficient.
set (l) to (length of [liste v] :: list)For others ones, see Fisher-Yates maybe.
set (i) to (pick random [1] to (l))
set (iv) to (item (i) of [liste v])
repeat ([2]*(l))
set (j) to (pick random [1] to (l))
set (item (i) of [liste v]) to (item (j) of [liste v])
set (i) to (j)
end
set (item (j) of [liste v]) to (iv)
See also more info on bias, here.
Greetz.
Dimitri
Last edited by dimitrip (Dec. 22, 2015 13:14:03)
- gtoal
-
1000+ posts
Shuffling Lists
How do you make it so that the program shuffles a list without repeating any existing values (e.g. You becomes Yuu)?
define Shuffle
set [each v] to [0]
repeat ((length of [cards v]) - (1))
change [each v] by (1)
Swap (each) (pick random (each) to (length of [cards v]))
end
Last edited by gtoal (Dec. 28, 2015 02:52:09)
- Discussion Forums
- » Help with Scripts
-
» Shuffling Lists