Skip to content

javascript array shuffler [fisher yates knuth durstenfeld]

Notifications You must be signed in to change notification settings

queviva/yacht-fisher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

javascript array shuffler [fisher yates knuth durstenfeld]

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages