random_generator 659 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/sh
  2. #set -x
  3. clear
  4. ###
  5. #
  6. # Author: Stéphane HUC
  7. # mail: devs@stephane-huc.net
  8. #
  9. # License: GNU/GPL 3
  10. #
  11. # Github: https://git.framasoft.org/hucste/tools
  12. #
  13. # Date: 2016/04/14
  14. #
  15. ###
  16. ###
  17. # generate random number
  18. ###
  19. pas="$1"
  20. rand_gen() {
  21. tr -dc 0-9 < /dev/urandom | head -c $1 | awk '{print int($1)}'
  22. }
  23. [ -z "$pas" ] && pas=$(shuf -i 4096-65535 -n 1)
  24. echo "pas: $pas"; sleep 1
  25. i=0;
  26. while [ "$i" -le "$pas" ]; do
  27. HEAD=$(rand_gen 2)
  28. RANDOM=$(rand_gen ${HEAD})
  29. echo "random: $RANDOM"
  30. nb=$(echo "$i * $RANDOM" | bc);
  31. printf "i:$i \t/ $pas \t nb: $nb\n";
  32. unset nb;
  33. i=$(($i + 1));
  34. [ $i -eq $pas ] && i=0
  35. done
  36. unset i