Re: TIFU by using Math.random()

2015-12-02 Thread Jan de Mooij
On Wed, Nov 25, 2015 at 7:59 PM, Chris Peterson 
wrote:

> On 11/25/15 5:51 AM, Xidorn Quan wrote:
>
>> After reading this article as well as some introduction from the
>> wikipedia, it seems to me that "xorshift+" is probably the best
>> algorithm to adopt, because it is simple, fast, and passes all tests
>> in TestU01 [1], which indicates it should also have a good quality.
>>
>
> We have an implementation of the xorshift128+ PRNG in
> mfbt/XorShift128PlusRNG.h from bug 1206356 that could be used.
>

I landed patches to use this RNG for Math.random() [0]. xorshift128+ does
very well in statistical tests and is very fast (faster than our previous
one actually). Interestingly, V8 and JSC are using the same algorithm now
(since a few days).

Jan

[0] https://bugzilla.mozilla.org/show_bug.cgi?id=322529
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: TIFU by using Math.random()

2015-11-25 Thread Boris Zbarsky

On 11/25/15 9:59 AM, Mike Hoye wrote:

Doing the wrong thing really fast is not hard.


You have now discovered the key optimization secret of web browsers.

-Boris

___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: TIFU by using Math.random()

2015-11-25 Thread Chris Peterson

On 11/25/15 5:51 AM, Xidorn Quan wrote:

According to the article, SpiderMonkey's PRNG is not much better than
V8's. It seems we are using a even older algorithm, although
ironically have a better result.

After reading this article as well as some introduction from the
wikipedia, it seems to me that "xorshift+" is probably the best
algorithm to adopt, because it is simple, fast, and passes all tests
in TestU01 [1], which indicates it should also have a good quality.


We have an implementation of the xorshift128+ PRNG in 
mfbt/XorShift128PlusRNG.h from bug 1206356 that could be used.



___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: TIFU by using Math.random()

2015-11-25 Thread Mike Hoye

On 2015-11-25 9:33 AM, Frederik Braun wrote:

On 25.11.2015 12:42, Philip Chee wrote:



Hopefully Spidermonkey's Math.random() is better.

Phil


There have been multiple insightful responses on HN and reddit/netsec.
The short version is, that Math.random() isn't providing statistically
good randomness, because JS benchmarks use it. So it has been optimized
for performance in most browsers.
That article's key takeaway is that the word "performance" doesn't 
really mean anything absent a bunch of context-specific qualifiers, and 
you're going to get bitten if you don't understand them. Doing the wrong 
thing really fast is not hard.


- mhoye
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: TIFU by using Math.random()

2015-11-25 Thread Xidorn Quan
According to the article, SpiderMonkey's PRNG is not much better than
V8's. It seems we are using a even older algorithm, although
ironically have a better result.

After reading this article as well as some introduction from the
wikipedia, it seems to me that "xorshift+" is probably the best
algorithm to adopt, because it is simple, fast, and passes all tests
in TestU01 [1], which indicates it should also have a good quality.

I'm not an expert on this, though.


[1] http://xorshift.di.unimi.it/

- Xidorn

On Wed, Nov 25, 2015 at 10:42 PM, Philip Chee  wrote:
> 
>
> Hopefully Spidermonkey's Math.random() is better.
>
> Phil
>
> --
> Philip Chee , 
> http://flashblock.mozdev.org/ http://xsidebar.mozdev.org
> Guard us from the she-wolf and the wolf, and guard us from the thief,
> oh Night, and so be good for us to pass.
> ___
> dev-platform mailing list
> dev-platform@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: TIFU by using Math.random()

2015-11-25 Thread Frederik Braun
On 25.11.2015 12:42, Philip Chee wrote:
> 
> 
> Hopefully Spidermonkey's Math.random() is better.
> 
> Phil
> 

There have been multiple insightful responses on HN and reddit/netsec.
The short version is, that Math.random() isn't providing statistically
good randomness, because JS benchmarks use it. So it has been optimized
for performance in most browsers.

Also, the person writing the post did not only want randomness, but
uniqueness. If someone wants unique, you should use a UUID-algorithm.
If all you need is a better PRNG use crypto.getRandomValues(), which is
providing cryptographically secure randomness.
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform