Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • Why do not use /dev/random? Commented May 26, 2021 at 7:07
  • 2
    why not use echo $RANDOM ? (unless you want to focus more on code than result) Commented May 26, 2021 at 7:20
  • 1
    Always /dev/urandom rather than /dev/random Commented May 26, 2021 at 8:43
  • 1
    Your a=$(($(date +%s%N)/1000000)) works for me, what problem do you have with it? Commented May 26, 2021 at 8:53
  • 1
    If you do $((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 2xx and 7xx for a while until it drifts to 3xx and 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. Commented May 26, 2021 at 16:17