RandomSource 代表密码学安全随机数的来源。它可以通过全局对象的 Crypto 获取:网页中的 Window.crypto,Workrt 里面的 WorkerGlobalScope.crypto。
RandomSource 不是一个接口,这个类型的对象不可以被创建。
属性
RandomSource 既没有定义也没有属性。
方法
RandomSource.getRandomValues()- 使用密码学可靠的随机值填充传递过来的
ArrayBufferView。
标准
| Specification | Status | Comment |
|---|---|---|
| Web Cryptography API | Recommendation | Initial definition |
浏览器兼容性
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| Basic support | 11.0 WebKit bug 22049 | (Yes) | 21 (21) [1] | 11.0 | 15.0 | 3.1 |
| Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|---|
| Basic support | 未实现 | 23 | (Yes) | 21.0 (21) | 未实现 | 未实现 | 6 |
[1] Although the transparent RandomSource is only available since Firefox 26, the feature was available in Firefox 21.
参见
- 通过
Window.crypto获取一个Crypto对象。 Math.random,一个非密码学安全来源的随机数。