#Java, 88 101
Java, 88 101
A basic Fisher-Yates shuffle does the trick. I get the feeling it'll be used pretty commonly here, since it's quick and easy to implement. There's some loop/assignment cramming here, but there's honestly not too much to golf; it's just short by nature.
void t(int[]s){for(int i=s.length,t,x;i>0;t=s[x*=Math.random()],s[x]=s[i],s[i]=t)x=i--;}
With some line breaks:
void t(int[]s){
for(int i=s.length,t,x;
i>0;
t=s[x*=Math.random()],
s[x]=s[i],
s[i]=t
)
x=i--;
}
This shuffles in place, modifying the original array s[]. Test program:
public class Shuffle {
public static void main(String[] args) {
int[] a = {1,2,3,4,5,6,7,8,9};
new Shuffle().t(a);
for(int b:a)
System.out.print(b+" ");
}
void t(int[]s){for(int i=s.length,t,x;i>0;t=s[x*=Math.random()],s[x]=s[i],s[i]=t)x=i--;}
}