作者imce (蜥蜴)
看板perl
標題[問題]這個有辦法簡化媽?
時間Thu Jul 13 22:03:11 2006
$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