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

  • Home
  • SEARCH
  • 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 9188201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:56:56+00:00 2026-06-17T19:56:56+00:00

I did some research before posting but seem to be at a lost (not

  • 0

I did some research before posting but seem to be at a lost (not too experienced in coding).

I am attempting to generate or compute a random number for certain time interval with Python. I’m not looking for full code, I want help using the time library if that is the correct one to use.

Pseudo-code:

Allow python [PC] to compute a random number for 3 seconds

——> Store the computed generation in a value (i can handle this)

I would then use the random generated value to link access a python list (which would be automatically generated via a random number generation as well but i can figure that out).

  • 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-06-17T19:56:57+00:00Added an answer on June 17, 2026 at 7:56 pm

    I’m not sure why you want to do this, but here’s how to compute many random numbers, throwing most of them away, and then using the last one after 3 seconds have elapsed.

    import random
    import time
    
    start = time.clock()
    while time.clock() - start < 3:
        random_number = random.randint(0,100)
    
    print random_number
    

    This pointlessly throws away about 2 million perfectly good random numbers on my machine.

    (And, as abarnert points out, this also maxes out one CPU core for the whole 3 seconds in a busy loop, which is very, very wasteful, but I thinks it’s what you were asking for?)

    EDIT: Updated to use time.clock instead of time.time, as suggested by abarnert again (thanks), because this seems to give better resolution across platforms and doesn’t suffer from problems when the system time is altered in the middle of the program running.

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

Sidebar

Related Questions

I did some research but all I could find was syncing data core with
I did some research but couldn't find the answer I was looking for so
I did some research but cannot find a definite approval or disapproval. What I
I did some research into the easiest/best way to generate a pdf in my
I apologize if this is covered somewhere. I did research before posting! okay, so
before posting the question i did my research for 10 days so really hope
I haven't posted on here before but I have tried to do some research
I did some research on this, but wasn't able to find any substantial answers,
I did some research about a question but didn't find any answer. And now,
I did some research and found that the only way to vertically center a

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.