OCaml Forge

Browse | Submit A New Snippet | Create A Package

Fisher-Yates Shuffle

Type:
Function
Category:
Other
License:
Other
Language:
Other Language
 
Description:
The Fisher-Yates shuffle (aka Knuth Shuffle) in OCaml.

Versions Of This Snippet:

Snippet ID Download Version Date Posted Author Delete
11.02008-08-03 23:10Martin Bishop

Download a raw-text version of this code by clicking on "Download Version"

 


Latest Snippet Version: 1.0

let shuffle a = for n = ((Array.length a) - 1) downto 0 do Random.self_init (); let k = Random.int (n + 1) in let temp = a.(n) in a.(n) <- a.(k); a.(k) <- temp done

Submit a new version

You can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..