Fast Tuple Shuffle (Fisher-Yates)

Fisher–Yates shuffle

shuffle(Tuple) ->
    shuffle(Tuple, size(Tuple)).

shuffle(Tuple, 1) ->
    Tuple;
shuffle(Tuple, N)->
    Random = erlang:phash2(os:timestamp(), N) + 1,
    A = element(N, Tuple),
    B = element(Random, Tuple),
    Tuple2 = setelement(N, Tuple, B),
    Tuple3 = setelement(Random, Tuple2, A),
    shuffle(Tuple3, N - 1).
 
19
Kudos
 
19
Kudos

Now read this

Ownership as code

In software development, ownership is a term that’s often thrown around but poorly understood. What does it mean to own something? Why is this something we strive to attain? At Samsung Ads, the engineering team had been growing very... Continue →