56 lines · 1.4 KB · Text
RawDownload
//-------------------------------------------------------------------// name: randomize()// desc: random number generation example...//       to show the effects of alternating between//       1) explicitly seeding the random number generator (RNG)//       -- AND --//       2) implicitly seeding the RNG with a practially//          unpredicable seed//// requires: chuck-1.5.0.4 or higher//// author: Ge Wang (https://ccrma.stanford.edu/~ge/)// date: Summer 2023//------------------------------------------------------------------- // explicit seed10513 => int EXPLICIT_SEED;// how many to print each round8 => int HOW_MANY;// how long to wait between each number100::ms => dur T; fun void generate( int howMany, dur T, int indents ){    int i;    repeat(howMany)    {        T => now;        repeat(indents) cherr <= " ";        <<< ++i, Math.random2(1,100) >>>;    }} while( true ){    // explicit seeding    <<< "--------------------------------------", "" >>>;    <<< "seeding RNG with", EXPLICIT_SEED, "SAME EACH TIME!" >>>;    <<< "--------------------------------------", "" >>>;    Math.srandom( EXPLICIT_SEED );    // generate    generate( HOW_MANY, T, 0 );     // wait a bit    5*T => now;            <<< "********************", "" >>>;    <<< "SHAKING THINGS UP!!!", "" >>>;    <<< "********************", "" >>>;    Math.randomize();    // generate    generate( HOW_MANY, T, 16 );     // wait a bit    5*T => now;    }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t