Knuth shuffle: Difference between revisions

m
→‎{{header|R}}: Syntax highlighting.
(→‎{{header|6502 Assembly}}: Overhauled this section with a solution that can work with any range of values)
m (→‎{{header|R}}: Syntax highlighting.)
Line 3,894:
===Original Fisher-Yates version===
<lang rrsplus>fisheryatesshuffle <- function(n)
{
pool <- seq_len(n)
Line 3,907:
}</lang>
===Knuth variation===
<lang rrsplus>fisheryatesknuthshuffle <- function(n)
{
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 rrsplus>knuth<-function(vec)
{
last<-length(vec)
331

edits