How to print out string at random interval
05/02/2018 12:08
Hello everyone,
I want to print out the string Hello World! to console at a randominterval, and the average length of the random interval is 1 minute whenthe string is printed out hundreds of times. Anyone know how to accomplishthis?
Thanks in advance,George

Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
05/02/2018 12:08 - What part are you having problems with? Deciding on the intervals orexecuting the print at the appropriate time?

Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
05/02/2018 12:08 - Thanks Thomas,
Your method is very good! I want to learn more about the theory and usageof nextGaussian method in Java. Can you recommend some online resources?
regards,George

Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
05/02/2018 12:08 - a java.util.Random instance has the nextGaussian() method, which returns a normally distributed with mean = 0, standard deviation = 1. multiplication/addition will move this value as you need it. for example:

double interval = 1000*60+MyRandom.nextGaussian()*1000*15;
will give you an interval in milliseconds, where about 65% of the values are between 45 seconds and 75 seconds. Make sense?
THN

Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
05/02/2018 12:08 - In article <f2a890aacd324328a5ab244cf1407fad@JavaKB.com>,
Also at <http://java.sun.com/>, find the API documentation for your version. Search for java.util.Random.nextGaussian(). Both example code and references are given.



Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
05/02/2018 12:08 - Thanks John,
Your advice is very helpful.


regards,George

Source is Usenet: comp.lang.java.help
Sign in to add a comment

Answer score: 5
05/02/2018 12:08 - Thanks John,
My difficulty is how to generate random length interval and make theaverage length of all generated hundreds of intervals be 1 minute. Can youhelp me with this point?
regards,George

Source is Usenet: comp.lang.java.help
Sign in to add a comment

eDiscover
Helpforce eDiscover provides technical articles updated each dayHelpforce eDiscover RSS feed contains the latest technical articles in RSS
Click the logo to go back to the main page
Search eDiscover
  
Categories

Click an icon to go to that category

Helpforce eDiscover contains articles about Microsoft Windows Helpforce eDiscover contains articles about Apple products and MacOS Helpforce eDiscover contains articles about Linux and POSIX operating systems Helpforce eDiscover contains articles about Helpforce Helpforce has a large variety of technical information and articles for you to read Helpforce eDiscover contains articles about databases, MYSQL, SQL Server Oracle Helpforce eDiscover contains articles about Java, JVM and the JRE Helpforce eDiscover contains articles about the QNX operating system Helpforce eDiscover contains articles about Oracle Solaris and Open Solaris Helpforce eDiscover contains articles about RISC OS, Acorn and the BBC Micro Helpforce eDiscover contains articles about Amiga and AmigaOS

Type your comment into the box below