time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (3134B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # reviveBasePRNG
     22 
     23 > Revive a JSON-serialized pseudorandom number generator (PRNG).
     24 
     25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
     26 
     27 <section class="intro">
     28 
     29 </section>
     30 
     31 <!-- /.intro -->
     32 
     33 <!-- Package usage documentation. -->
     34 
     35 <section class="usage">
     36 
     37 ## Usage
     38 
     39 ```javascript
     40 var reviveBasePRNG = require( '@stdlib/random/base/reviver' );
     41 ```
     42 
     43 #### reviveBasePRNG( key, value )
     44 
     45 Revives a JSON-serialized pseudorandom number generator (PRNG).
     46 
     47 ```javascript
     48 var parseJSON = require( '@stdlib/utils/parse-json' );
     49 var randu = require( '@stdlib/random/base/randu' );
     50 
     51 var str = JSON.stringify( randu );
     52 
     53 var rand = parseJSON( str, reviveBasePRNG );
     54 // returns <Function>
     55 ```
     56 
     57 For details on the JSON serialization format, see the `.toJSON()` method for, e.g., [`randu()`][@stdlib/random/base/randu].
     58 
     59 </section>
     60 
     61 <!-- /.usage -->
     62 
     63 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     64 
     65 <section class="notes">
     66 
     67 </section>
     68 
     69 <!-- /.notes -->
     70 
     71 <!-- Package usage examples. -->
     72 
     73 <section class="examples">
     74 
     75 ## Examples
     76 
     77 <!-- eslint no-undef: "error" -->
     78 
     79 ```javascript
     80 var randu = require( '@stdlib/random/base/randu' );
     81 var parseJSON = require( '@stdlib/utils/parse-json' );
     82 var reviveBasePRNG = require( '@stdlib/random/base/reviver' );
     83 
     84 var rand;
     85 var str;
     86 var r1;
     87 var r2;
     88 var i;
     89 
     90 // Progress the PRNG state...
     91 for ( i = 0; i < 100; i++ ) {
     92     r1 = randu();
     93 }
     94 
     95 // Serialize the PRNG as a JSON string:
     96 str = JSON.stringify( randu );
     97 
     98 // Revive the JSON-serialized PRNG:
     99 rand = parseJSON( str, reviveBasePRNG );
    100 if ( rand instanceof Error ) {
    101     console.error( rand.message );
    102 }
    103 
    104 // Generate duplicate sequences...
    105 for ( i = 0; i < 100; i++ ) {
    106     r1 = randu();
    107     r2 = rand();
    108     console.log( '%d == %d ? %s', r1, r2, ( r1 === r2 ).toString() );
    109 }
    110 ```
    111 
    112 </section>
    113 
    114 <!-- /.examples -->
    115 
    116 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    117 
    118 <section class="references">
    119 
    120 </section>
    121 
    122 <!-- /.references -->
    123 
    124 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    125 
    126 <section class="links">
    127 
    128 [@stdlib/random/base/randu]: https://www.npmjs.com/package/@stdlib/random/tree/main/base/randu
    129 
    130 </section>
    131 
    132 <!-- /.links -->