본문 바로가기
프로...Linux

[sh] bourne shell(sh)에서 rand 사용법

by 크크다스 2018. 11. 6.
반응형

참고> https://www.unix.com/shell-programming-and-scripting/267297-generating-posix-random-number.html


예제>

root>:/www/cgi-bin# cat /tmp/xx.sh

#!/bin/sh

for n in {1..4}

do

        TMP=$(awk ' BEGIN { srand(); printf( "%d %d\n", 16 * rand(), 16 * rand() ); }')

        byteone=${TMP% *}; bytetwo=${TMP#* }

        echo "$byteone $bytetwo"

        #sleep 1

done

root>:/www/cgi-bin# /tmp/xx.sh

0 5

root>:/www/cgi-bin# /tmp/xx.sh

3 2

root>:/www/cgi-bin# /tmp/xx.sh

6 7

root>:/www/cgi-bin# /tmp/xx.sh

12 6

root>:/www/cgi-bin#



반응형