Question

In: Computer Science

Can someone give me a detailed explanation as to what   Random generator = new Random(); Thread.sleep(generator.nextInt(1001));...

Can someone give me a detailed explanation as to what  

Random generator = new Random();

Thread.sleep(generator.nextInt(1001)); does in java?

Solutions

Expert Solution

Random generator = new Random();

Thread.sleep(generator.nextInt(1001));

1) Random generator = new Random();

This statement creates an instance of random class to generate a random number .
Random generator can only be generated using the object of random class.

The object created here is "generator".

2) Thread.sleep(generator.nextInt(1001));

Here, generator.nextInt(1001) produces a random integer between 0 and 1001.

Thread.sleep() - This function is used to pause the execution of the current thread.

Threads are used to run multiple processes at the same time.

Say for example we have a loop to print 0 to 10000. and a loop to print hello thousand times.

We can run these tasks parallel to each other using threads or we can pause one task for a certain time and execute the other thread.

Thread.sleep(time) - time is the parameter required to specify the amount of time the thread must be paused for.

In the above case, it will be a random milli-second between 0 to 1001 - generated by the random function above.

Please comment below if you have any queries.
Please do give a thumbs up if you liked the answer thanks :)


Related Solutions

Hello! Can someone please give me an in depth explanation of a SWOT please? I know...
Hello! Can someone please give me an in depth explanation of a SWOT please? I know the basic 4 but it didn’t go well. My SWOT is on Glossier.
Can someone please give me credited sources about police robotics and new technology.
Can someone please give me credited sources about police robotics and new technology.
Can someone give me an example an non example of coefficient?
Can someone give me an example an non example of coefficient?
Can someone give me a list of conditions for a market to be efficient
Can someone give me a list of conditions for a market to be efficient
How can we control the speed of Synchronous an AC Generator and give me a picture...
How can we control the speed of Synchronous an AC Generator and give me a picture of Synchronous an AC Generator regarding of what you are planning to say about controlling the speed? Give me details as much as you can.
can someone give me a brief background on the Ukraine healthcare system?
can someone give me a brief background on the Ukraine healthcare system?
How do I relate transcription and transfer of energy? Please give me detailed explanation! Thanks
How do I relate transcription and transfer of energy? Please give me detailed explanation! Thanks
Stock Investing Question Can someone give me a simplified explaination of what the below article is...
Stock Investing Question Can someone give me a simplified explaination of what the below article is saying? I am doing a project for a class that is supposed to analyze if investing in the company "Jones Energy" is a good idea. https://globenewswire.com/news-release/2018/02/12/1339471/0/en/Jones-Energy-Prices-Offering-of-450-Million-of-9-25-Senior-Secured-First-Lien-Notes.html
Multiple Linear Regression - Omitted Variable bias. Can someone provide me with an intuitive explanation of...
Multiple Linear Regression - Omitted Variable bias. Can someone provide me with an intuitive explanation of ommitted variable bias.
Econometrics: Can someone please give a clear, concise and intuitive explanation of the rank of a...
Econometrics: Can someone please give a clear, concise and intuitive explanation of the rank of a matrix and how to find the rank using examples. WITHOUT REFERENCE TO ECHELON FORM.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT