| Anonymous | Login | Signup for a new account | 2013-06-19 03:32 CEST | ![]() |
| Main | My View | View Issues | Change Log | Roadmap |
| View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||||
| ID | Project | Category | View Status | Date Submitted | Last Update | ||||||
| 0005183 | OCaml | OCaml general | public | 2010-11-29 15:03 | 2011-05-20 14:45 | ||||||
| Reporter | warwick | ||||||||||
| Assigned To | doligez | ||||||||||
| Priority | normal | Severity | feature | Reproducibility | always | ||||||
| Status | assigned | Resolution | open | ||||||||
| Platform | OS | OS Version | |||||||||
| Product Version | 3.12.0 | ||||||||||
| Target Version | Fixed in Version | ||||||||||
| Summary | 0005183: Array shuffle function in random module | ||||||||||
| Description | It would be useful to include a function within the Random module to shuffle an array. I think this is a fairly fundamental operation and therefore worthy of inclusion in the OCaml standard library rather than having to download/install an extension module to do it. It's also a function that's significantly error-prone to implement, so having a correct version in the standard library would be a handy so that individual programmers don't have to code this function from scratch in their applications. | ||||||||||
| Additional Information | (** [shuffle a] shuffles an array, giving a uniform random distribution *) let shuffle a = for i = pred (Array.length a) downto 1 do let j = Random.int (succ i) in if i <> j (* faster to omit this test with arrays of about 100000 elements or more *) then ( let tmp = Array.unsafe_get a i in Array.unsafe_set a i (Array.unsafe_get a j); Array.unsafe_set a j tmp ) done | ||||||||||
| Tags | No tags attached. | ||||||||||
| Attached Files | |||||||||||
Issue History |
|||
| Date Modified | Username | Field | Change |
| 2010-11-29 15:03 | warwick | New Issue | |
| 2011-05-20 14:45 | doligez | Status | new => assigned |
| 2011-05-20 14:45 | doligez | Assigned To | => doligez |
| Copyright © 2000 - 2011 MantisBT Group |