W3C home > Mailing lists > Public > public-html-ig-zh@w3.org > February 2011

(wrong string) 長度問題

From: John Hax <johnhax@gmail.com>
Date: Sat, 12 Feb 2011 02:13:46 +0800
Message-ID: <AANLkTik=hu5KkLCZB824+z1QoSF98v=HGpMNReRu6Zew@mail.gmail.com>
To: Timothy Chien <timdream@gmail.com>
Cc: (wrong string) 樂會ML <public-html-ig-zh@w3.org>, Kang-Hao Lu <kennyluck@w3.org>
ӦtoString(r)㷨ͬr=10ecma淶ûй涨㷨

ǹ۲쵽ijȣΪԭǶƣrΪżʱdzתֱr/2һתɣβϲ0ɡrΪʱ31͸ˣ

0.5ƾ0.1(2)Ľƾ0.216ƾ0.8

ƾ0.11111111111111111111111111111...

FFƳȣС34λrȲͬǰЧλģwebkitС1024λ

ҸFF㷨һЩ




2011/2/11 Timothy Chien <timdream@gmail.com>

> ǰһʽܑжֻ webkit yԇ] Firefox y
> Y demo ĕrը_ orz  ...
>
> lFІ}ijʽa@
> var randomString = Math.random().toString(16).substr(2); // substr(2) ǰǰ
> "0." õ
>
>  WebkitrandomString Lȕ 7  8 ֮g
> Firefox t 13  14 .......
>
> njеijʽa׌ randomString Lȹ̶ 16
>
> var randomString = (function () {
>         var num = '';
>         while (num.length < 16) {
>             num += Math.random().toString(16).substr(2);
>         }
>         return num.substr(0,16);
>     })();
>
> ߀Ҫ{ʲNɂg[@NIJ
> rҺͬµĽYՓǣ
> mf ECMAScript [1] Ҏ Number ̈́eĔ  64-bit format IEEE 754 value0~1 ֮g
> 2^64 ֵ [2]
>  webkit ļفyaõеλ toString(16) ֮Lȸ Firefox һӡ
> ֻԼҲ]СģԞ random() СcLǹ̶ġ
>
> ^أһ toString(radix) [3]  radix (Mλ)
> lFWebkit aλLһ^̡@鲻һnjģ
> redix = 31 Ԓwebkit LLԵ 1024Firefox ֻ 11
>
> My Orz ֮_ spec  implantation eԒԈȥ
> λMЛ]N idea
>
> NҲԁG WTFjs XDDDD
>
>
> Tim
>
> [1] http://www.ecmascript.org/docs.php, 4.3.19, pdf page 5
> [2]
> https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Math/random
> [3]
> https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Number/toString
>
>
Received on Friday, 11 February 2011 18:14:19 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:43:46 UTC