看板 Perl 關於我們 聯絡資訊
$hitno[$_]=$_ foreach(0..9); foreach(0..9) { $ran=int(rand()*9+1); $temp=$hitno[$_]; $hitno[$_]=$hitno[$ran]; $hitno[$ran]=$temp; } 有辦法簡化媽?目的是要取10個不同的亂數 $ran=int(rand()*9+1),+1的目的是第一個數字不能為0 各位高手幫忙簡化一下吧 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.120.15.17
LiloHuang:print join $/,(sort{rand>.5?-1:1}1..10); 07/14 01:33
darenhu:perlfaq4: How do I shuffle an array randomly? 07/14 07:55
darenhu:use Util::List qw(shffle); @hitno = shuffle 0..9; 07/14 08:05
darenhu:更正: use List::Util qw(shuffle); 才對 07/14 08:08