Knuth shuffle: Difference between revisions
m
→{{header|R}}: Syntax highlighting.
Puppydrum64 (talk | contribs) (→{{header|6502 Assembly}}: Overhauled this section with a solution that can work with any range of values) |
ReeceGoding (talk | contribs) m (→{{header|R}}: Syntax highlighting.) |
||
Line 3,894:
===Original Fisher-Yates version===
<lang
{
pool <- seq_len(n)
Line 3,907:
}</lang>
===Knuth variation===
<lang
{
a <- seq_len(n)
Line 3,930:
===Short version===
After accounting for R being 1-indexed rather than 0-indexed, it's not hard to implement the pseudo-code given in the task almost exactly:
<lang
{
last<-length(vec)
|