Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Increasing random() function speed.

36 views
Skip to first unread message

H e

unread,
Jan 18, 2021, 6:07:10 AM1/18/21
to
I have noticed, that JavaScript Math.random() is a little bit slow.

My function:

Use smallest possible time, create digit of it. Make 10 digit number of it.
Use function 2^a1+3^a2+...+11^a10 to create next digit with suming it until 1 digit. Function should always remember a2,...,a10, which will be next a1,...,a9. When the function is called in the same second(smallest clock unit usually), then increase a reminder variable digit when function is called again. When not, use next time produced digit as next a10.

If it is already made, then please give me references.


Mina, jah mina, kes küll muu.

(372) 6861327

David Brown

unread,
Jan 18, 2021, 6:15:16 AM1/18/21
to
On 18/01/2021 12:07, H e wrote:
> I have noticed, that JavaScript Math.random() is a little bit slow.

Please stop posting this. You are wrong - you simply don't understand
how to benchmark and measure speed. Once you have learned that, you
will find that the function is extremely fast - so much so that the time
is negligible compared to the time it takes a JavaScript engine to call
a function.

>
> My function:
>
> Use smallest possible time, create digit of it. Make 10 digit number of it.
> Use function 2^a1+3^a2+...+11^a10 to create next digit with suming it until 1 digit. Function should always remember a2,...,a10, which will be next a1,...,a9. When the function is called in the same second(smallest clock unit usually), then increase a reminder variable digit when function is called again. When not, use next time produced digit as next a10.
>
> If it is already made, then please give me references.
>

Making a good random number generator is not easy. It is hard to make
it at least reasonably random, and hard to make it efficient. You are
not qualified to do either - it takes a lot of mathematical knowledge
and experience, as well as solid understanding of low-level coding.

It can be fun to /try/ to make a random number generator, and you can
learn a lot from experimenting and playing around. But don't kid
yourself that /you/ can do something better than the standard library in
JavaScript (or any other language). Maybe one day you will reach that
level, but it's twenty years down the road at least.

Learn to benchmark and to experiment.

Message has been deleted

H E

unread,
Jan 18, 2021, 9:42:55 AM1/18/21
to
Seems interesting, David .......

I counted the maximum possible random numbers in 1 second.
I got this from thinking about the formula 2^a1+3^a2+...+11^a10.
It is 10^10.

H E

unread,
Jan 18, 2021, 9:45:17 AM1/18/21
to
Actually the formula 2^a1+3^a2+...+11^a10 can be appended with something like:
+12^a11 and so on.
On the smallest case the result is 10^11.

David Brown

unread,
Jan 18, 2021, 10:14:44 AM1/18/21
to
You are not making any sense at all, in any way. There is no limit to
the number of random numbers (or pseudo-random numbers) that can be
generated in any given time (not until you start considering quantum
mechanics, minimum energies for computations, maximum energy densities,
and that sort of thing).

I don't know what you think that "formula" means, but repeatedly posting
the same gibberish won't help. If you have a question, post it. But
you'll have to explain what you are trying to do.

H e

unread,
Jan 18, 2021, 1:29:13 PM1/18/21
to
0 new messages