7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

リストをシャッフルする

Posted at

たまーに使う、リスト要素をランダムに並べ替える方法を、いくつかの言語について調べてみた。

#####Perl

use List::Util qw/shuffle/;

say shuffle 0..9;

List::Utilにshuffleがある

#####Python

import random

list = range(10)
random.shuffle(list)
print list

#####Ruby

list = (0..9).to_a
puts list.shuffle

#####JavaScript

var list = [0,1,2,3,4,5,6,7,8,9];
console.log(_.shuffle(list));

underscore.js

自前でやりたい時は、Fisher-Yates法というのを使うのがよいようだ

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?