Pacific-Design.com

    
Home Index

1. Bash

2. Random URL

+ Random 150

+ Random Pick

Bash / Random URL /


#!/bin/bash
#----------------------------------------------------------------#
shuffle() {
   local i tmp size max rand

   size=${#array[*]}
   max=$(( 32768 / size * size ))

   for ((i=size-1; i>0; i--)); do
      while (( (rand=$RANDOM) >= max )); do :; done
      rand=$(( rand % (i+1) ))
      tmp=${array[i]} array[i]=${array[rand]} array[rand]=$tmp
   done
}
#----------------------------------------------------------------#
display() {
   for i in "${array[@]}"
   do
     echo $i
   done
}
#----------------------------------------------------------------#

IFS=$'\n' read -d '' -r -a array < lat-long.dat
# echo "${array[@]}"

for i in $(seq 10 15)
do
  echo "$i times"
  shuffle
  display
  sleep 3
done

#----------------------------------------------------------------#