Ok so my problem is as followed, I wish to pass this :-
echo $(($(date +%s%N)/1000000))
Into a variable "a" to it can be added to an array, something like this :-
The reason I am doing this is a would like 4 random digits to play with (Random numbers). I have produced this bash script to show an example.
#!/bin/bash for (( c=0; c<=10; c++)) do echo $(($(date +%s%N)/1000000)) sleep .5 done
Which outputs :- (Ignore the first 9 digits)
1622001937610 1622001938249 1622001938758 1622001939267 1622001939774 1622001940282 1622001940790 1622001941299 1622001941807 1622001942315 1622001942823
Now I wanted to add the results of just one instance of this into an array, index from the last 9th digit to receive 4 random digits based on nano second time.
How ever I don't seem to have full grasped the syntax used within bash to achieve the result.
Could I possible call
date +%s%N)/1000000 straight into an array? As my idea was to create and empty array and then just append the result into the array, and index from the 9th number. And pass the result into a second variable from there I can work on.
Just learning to turn the result of
date +%s%N)/1000000 into a variable would be of great help.
Sorry to be a pain. Any thank you in advanced.
echo $RANDOM? (unless you want to focus more on code than result)
a=$(($(date +%s%N)/1000000))works for me, what problem do you have with it?
$((ns / 1000000)), you drop off the six rightmost digits, that is the micro- and nanoseconds, leaving a millisecond timestamp, which isn't that random. E.g. if we look at the output you have, the three last digits alternate between
7xxfor a while until it drifts to
8xx. You could use
$(( ns % 1000000 ))to take the remainder instead, keeping the six lowest-order digits, but then the clock granularity might not be good enough for all of those to be meaningful either.