Skip to content

Latest commit

 

History

History
40 lines (26 loc) · 875 Bytes

README.md

File metadata and controls

40 lines (26 loc) · 875 Bytes

scrambiliare

yacht-fisherman array scrambler

bite here

this single line:

    const yacht = (v, r=[...v]) => v.map(() =>
        r.splice(~~(Math.random() * r.length), 1)[0]
    );

will produce a scrambled array without bias; find out why!

this silly thing:

    const yacht-stenshuffeld = v =>
        
        v.map((x, i, r,
        
            j = ~~(Math.random() * (r.length - i)) + i
            
        ) => ([x, r[j]] = [r[j], x], x)
        
    );

also one line, will produce a forward running, more conventional, durstenshuffle which does not destroy the original array - incase you should want such a thing

discover why