Don’t bother… some is slow, very slow when lists gets bigger than 5,000. It’s an real turning point though. Also you’re using the card-shuffle-technique for only 5,000 of the 20,000 cards. So the last card, card #5,000, has only 25% of a collision which makes the total random generated number somewhere around 5,700. Because random number is much faster than some for bigger lists with minor fine tuning you can make in this particular situation random command faster.
When you would have a real card shuffle deck, then indeed it would have so much collisions that the last card of a 5,000 has 99.95% chance of a colision and the average rng is then around 50,000. So like I said, for this particular situation when you only need to shuffle 25% of a complete deck, random number is the way to go. Then some is the way to go because some has no collisions at all and it will beat rng just by it’s efficiency, not by it’s performance.
However the overhead of reading, splitting, joining and writing to a file of 20.000 lines (2MB in file size) takes 90% of all execution time. So I could post a way that’s more than 2 times faster than using some, the total amount of execution time will be shortened by less than 5%.
edit: example codes to compare:
here an version using some:
script linearList
property array : {}
end script
script randomList
property array : {}
end script
set linearList's array to {}
set randomList's array to {}
repeat with x from 1 to 20000
set end of linearList's array to x
end repeat
repeat 5000 times
set seed to some integer of linearList's array
set item seed of linearList's array to missing value
set end of randomList's array to seed
end repeat
return
Here an version using random command and using an boolean array.
script linearList
property array : {}
end script
script randomList
property array : {}
end script
set linearList's array to {}
set randomList's array to {}
repeat 20000 times
set end of linearList's array to false
end repeat
set countRandomNumbers to 0
repeat until countRandomNumbers = 5000
set seed to random number from 1 to 20000
if not item seed of linearList's array then
set item seed of linearList's array to true
set end of randomList's array to seed
set countRandomNumbers to countRandomNumbers + 1
end if
end repeat
return
Like I said, the solution work’s best with an 1:4 ratio like the TS asks. When you use a deck with 100,000 card and pick randomliy 25,000 the solution is still fast, unlike some.