Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6676181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:57:17+00:00 2026-05-26T03:57:17+00:00

The following won’t work: /bin/sleep $(printf .%02ds $(( $RANDOM % 100 ))) POSIX sleep

  • 0

The following won’t work:

/bin/sleep $(printf ".%02ds" $(( $RANDOM % 100 )))
  1. POSIX sleep supports only integral seconds
  2. there is no $RANDOM

I could emulate random by:

RAND255=$(od -An -N1 -t u1 /dev/urandom)

Another option is to write a small C program that utilizes usleep() and *rand*() as suggested by @dmckee and @Keith Thompson. Deploying such program might not be always possible.

Is there a better way i.e., is there an alternative for sleep in POSIX that accept fractions of a second other than a hand-written C program and is there a better way to emulate $RANDOM other than od?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:57:18+00:00Added an answer on May 26, 2026 at 3:57 am

    In your first command, if $RANDOM % 100 is 6, for example, it will invoke /bin/sleep .6s; you want /bin/sleep .06s.

    In the second command, od -An -N1 -t u1 /dev/random seems to print a number in the range 0..255 — and the command itself can delay for a long time if /dev/random runs out of entropy. Use /dev/urandom instead.

    I’d write a small C program that calls usleep() (assuming that compiling it and deploying the executable is feasible).

    EDIT:

    As far as I can tell, the answer to your (updated) question is no.

    POSIX doesn’t guarantee /dev/urandom, so your od command isn’t portable to all POSIX systems. I don’t believe POSIX specifies any command that can sleep for fractional seconds. It does specify the nanosleep() function, but if you can’t necessarily deploy a C program that doesn’t help. POSIX awk has no sleep function. Perl is not POSIX.

    Your options are: (1) sleep only for whole seconds, or (2) use a non-portable method.

    What environment(s) do you need this for?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone enlighten me why the following won't work? $ groups staff btgroup $
Can anyone enlighten me as to why the following code won't work in IE7
the following runapplication won't work Private Sub RunApplication(ByVal ProgName As String) // String of
Can anyone tell me why the following won't work? It complains of a syntax
Why is it that the following code won't work: endDate.AddDays(7-endDate.DayOfWeek); While this will: endDate.AddDays(0-endDate.DayOfWeek
So the following won't work: var Foo = { array1 : ['apples', 'oranges', 'grapes'],
The following code won't work if i replace id with variable. I tried different
I understand that the following code won't work Float a=3 because its translated as
Can anyone explain why following code won't compile? At least on g++ 4.2.4. And
I have the following code that won't compile and although there is a way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.