Hello,
I have written a function that returns a random number in dependence of the
time running on the current system. The problem is that initializing two
variables with this function _one after another_, returns always the same
result:
function rndnumber () {...}
number1 = rndnumber();
number2 = rndnumber(); // number1=number2 !
I conclude that the initialization process is actually happening in the same
millisecond, which is a problem. Therefore, I would like to make the program
sleep (or call it wait ;-) for a while (e.g. some 10ms). How can I do that?
Thx a lot in advance.
Regards
Alexander 4 19382
Alexander Erlich wrote: Hello,
I have written a function that returns a random number in dependence of the time running on the current system. The problem is that initializing two variables with this function _one after another_, returns always the same result:
function rndnumber () {...}
number1 = rndnumber(); number2 = rndnumber(); // number1=number2 !
I conclude that the initialization process is actually happening in the same millisecond, which is a problem. Therefore, I would like to make the program sleep (or call it wait ;-) for a while (e.g. some 10ms). How can I do that?
Thx a lot in advance.
Regards Alexander
You can't make JavaScript sleep or wait, but you can delay execution of
a particular block of code using
intPID = setTimeout( strCode, intMilliseconds )
Beware that any code that follows the setTimeout call will still be
executed -- it is a non-blocking function call. It will likely be
executed to completion before the strCode code is executed.
It will look vaguely like another thread is running simultaneously--
this is not exactly the case-- but thinking of it in that manner can be
helpful sometimes and harmful others.
Alexander Erlich wrote: Hello,
I have written a function that returns a random number in dependence of the time running on the current system. The problem is that initializing two variables with this function _one after another_, returns always the same result:
function rndnumber () {...}
number1 = rndnumber(); number2 = rndnumber(); // number1=number2 !
I conclude that the initialization process is actually happening in the same millisecond, which is a problem. Therefore, I would like to make the program sleep (or call it wait ;-) for a while (e.g. some 10ms). How can I do that?
Thx a lot in advance.
Regards Alexander
By the way, if setTimeout isn't the solution, give us the code for
rndnumber and we'll see if we can't find the problem.
Alexander Erlich said: I have written a function that returns a random number in dependence of the time running on the current system.
Javascript provides a random function: http://www.jibbering.com/faq/#FAQ4_22
JRS: In article <d7************ *@news.t-online.com>, dated Wed, 1 Jun
2005 19:55:20, seen in news:comp.lang. javascript, Alexander Erlich
<JR********@web .de> posted : I have written a function that returns a random number in dependence of the time running on the current system. The problem is that initializing two variables with this function _one after another_, returns always the same result:
function rndnumber () {...}
number1 = rndnumber(); number2 = rndnumber(); // number1=number2 !
I conclude that the initialization process is actually happening in the same millisecond, which is a problem.
(a) While the unit of new Date() is a millisecond, the update interval
can be as much as 55 milliseconds.
(b) FAQ 4.22.
(c) <URL:http://www.merlyn.demo n.co.uk/js-randm.htm>.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Thomas Carter |
last post by:
Is it possible, in an OS-independent way, to suspend a C program for some
specified amount of time, in such a way that CPU load, due to this
program, while remaining suspended, is non-existant or, failing that,
minimal?
|
by: Simon Johnson |
last post by:
Recently, a thread appeared which asked how to create a "catch all" method
for when
an exception occurs within a program. The solution given only works for
Windows Forms applications, as far as i can tell, is it possible to do the
same with a console application?
Simon.
|
by: Karlo Lozovina |
last post by:
Consider this short script:
---
from time import time, sleep
st = time()
print 'Start: %f, ' % st,
sleep(10)
sp = time()
print 'Stop: %f, Duration: %f' % (sp, (st - sp))
|
by: Perecli Manole |
last post by:
I am having some strange thread synchronization problems that require me to
better understand the intricacies of Monitor.Wait/Pulse.
I have 3 threads. Thread 1 does a Monitor.Wait in a SyncLock block
protecting a resource. Thread 2 and 3 also have a SyncLock block protecting
the same resource and after executing some code in their blocks they both do
a Monitor.Pulse to hand of the locked resource back to thread 1.
While thread 1 has...
|
by: many_years_after |
last post by:
Hi, pythoners:
There is a problem I couldn't dispose. I start a thread in the my
program. The thread will do something before executing time.sleep().
When the user give a signal to the main thread (such as click the 'end'
button or close the window), the thread should end it's running. But
how to end the threading when it's sleeping? I set an flag to the
thread, but it doesn't work.
I also thought to put 'time.sleep()' to the main...
| |
by: cozsmin |
last post by:
hello , as u know wait() and notify() will not thow an exception if the method that calls them has the lock , or esle i misundrestood java :P
this is the code that throws (unwanted) exceptions :
(or u can download it from :
http://www.geocities.com/mndt_0/files/WaitingForThread.java
at this link it has the spaces )
|
by: =?Utf-8?B?Vmlua2k=?= |
last post by:
Hello Everyone,
I am not sure what am I doing wrong here. I spend almost whole day working
on this. I am trying to set focus on the process that I started by
Process.start. Below is my code
Process process;
process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
|
by: Buckaroo Banzai |
last post by:
Hello, newbie here...
I'm writing this program but when I click the start button which should initiate either the Hare or the Tortoise, it does not, this is the first time I use threads, so the problem might be the way I'm passing the value.
can someone please take a look at this code and maybe give me some guidance on what I'm doing wrong.
Please note there are 3 separate files with the corresponding classes, I separated it with ===>...
|
by: RedWiz |
last post by:
Hi
i have to develop a multihreaded php application on linux, then through
pcntl_fork and wait.
I tried it, but there something going wrong, i think.
The difference whit other languages like c and python is that the wait
cannot handle correctly all signals from dead children in two cases:
1 - two or more children dies (about) at the same time time
2 - the chidren dies before pcntl_wait start
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |