I am trying to generate a large amount of random integers and I want to write them to a text file, which will then be used as a standard input for a C program then re-do that process but with a larger amount of random integers.
This is what I currently have:
declare -a numbers=(100 1000 10000 20000 30000 40000 50000);
for number in ${numbers[*]}
do
for z in $(seq 1 $number)
do
shuf -i 0-99 -n 1 >> tests.txt
echo '\n' >> tests.txt
done
ksm.exe 50 < tests.txt
done
exit 0
I currently have a couple of issues. Firstly each random value is not being placed onto a new line in the text file which is necessary for my program. Secondly the process of generating random numbers is very slow, is there a quicker method of doing this? I am a beginner in regards to Bash so i'm not quite sure if I've approached this problem in the correct way, so any help would be much appreciated! Thank you.
Aucun commentaire:
Enregistrer un commentaire