scripting:nonportable

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
scripting:nonportable [2017/03/13 08:31]
whetu [Special variables]
scripting:nonportable [2019/08/30 16:25]
ersen use a for loop instead of while for gawk command
Line 84: Line 84:
 <​code>​ <​code>​
 # '​gawk'​ can produce random numbers using srand(). ​ In this example, 10 integers between 1 and 500: # '​gawk'​ can produce random numbers using srand(). ​ In this example, 10 integers between 1 and 500:
-randpm=$(gawk -v min=1 -v max=500 -v nNum=10 '​BEGIN{srand(systime() + PROCINFO["​pid"​]);​ i = 0; while (i < nNum) { print int(min+rand()*(max-min)); ++i} }')+randpm=$(gawk -v min=1 -v max=500 -v nNum=10 'BEGIN { srand(systime() + PROCINFO["​pid"​]); ​for (i = 0; i < nNum; ++i) {print int(min + rand() * (max - min)} }')
  
 # '​nawk'​ and '​mawk'​ does the same, but needs a seed to be provided for its rand() function. ​ In this example we use $(date) # '​nawk'​ and '​mawk'​ does the same, but needs a seed to be provided for its rand() function. ​ In this example we use $(date)
  • scripting/nonportable.txt
  • Last modified: 2019/08/30 16:30
  • by ersen