On Mon, Mar 10, 2003 at 03:15:17PM +1300, Hamish McBrearty wrote:
> @array=(1,2,3,4);
>
> $times=int(rand 49)+1;
>
> while ($times<50){
>
>
> $a=int(rand 3);
>
> $b=$array[$a];
>
> splice(@array, $a, 1);
>
> unshift(@array,$b);
>
> #print "$times\n";
>
> $times++;
> }
> foreach $stuff (@array){
> print $stuff;
> print "\n";
> }
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv) {
int array[4] = {1,2,3,4};
int times = 1 + (int)(49.0 * rand() / (RAND_MAX + 1.0));
int a,b,i;
while (times < 50) {
a = 1 + (int)(3.0 * rand() / (RAND_MAX + 1.0));
b = array[a];
for (i=a;i>0;i--) { array[i] = array[i-1]; }
array[0] = b;
times++;
}
for (i=0;i<=3;i++) {
printf("%d\n", array[i]);
}
exit(0);
}
WARNING: rand() sucks, and will return the same numbers for each invocation
of this program. I dont have time to go find the better method :P (supposed
to be working)
Mike.
--
Mike Beattie <[EMAIL PROTECTED]> ZL4TXK, IRLP Node 6184
Contentsofsignaturemaysettleduringshipping.