ZealOS/src/Demo/RandDemo.CC

65 lines
1.2 KiB
HolyC
Raw Normal View History

2020-02-15 20:01:48 +00:00
U0 RandPts()
{
I64 i;
F64 t0=tS;
do {
for (i=0;i<1024;i++) {
gr.dc->color=RandU16&15;
GrPlot(gr.dc,RandU32%GR_WIDTH,RandU32%GR_HEIGHT);
}
Yield;
} while (tS-t0<1);
DCFill;
2020-02-15 20:01:48 +00:00
}
U0 RandDemo()
{
I64 i;
2020-02-15 20:01:48 +00:00
2020-03-01 01:59:50 +00:00
"Seed(0) will do timer XORed random numbers. "
"A task starts with $LK,"Seed(0)",A="FF:::/Kernel/KTask.CC,Seed("$ by default.\n";
PressAKey;
Seed;
RandPts;
DCFill;
2020-02-15 20:01:48 +00:00
"\nSeed(num) will do deterministic, non-timer random numbers starting at "
2020-03-01 01:59:50 +00:00
"a specific seed. You can run a specific video game over and over "
"by typing Seed(num) at the cmd line before the game.\n";
PressAKey;
Seed(1);
RandPts;
DCFill;
2020-02-15 20:01:48 +00:00
"\n\n\nWatch when we specify specific seeds:";
2020-02-15 20:01:48 +00:00
"\n\nSeed(1);\n";
Seed(1);
for (i=0;i<5;i++)
"%d: %d\n",i,RandI16;
2020-02-15 20:01:48 +00:00
"\nSeed(2); Different, right?\n";
Seed(2);
for (i=0;i<5;i++)
"%d: %d\n",i,RandI16;
2020-02-15 20:01:48 +00:00
"\nSeed(1); Repeats earlier values.\n";
Seed(1);
for (i=0;i<5;i++)
"%d: %d\n",i,RandI16;
2020-02-15 20:01:48 +00:00
"\nSeed(0); Zero is special.\n";
Seed(0);
for (i=0;i<5;i++)
"%d: %d\n",i,RandI16;
2020-02-15 20:01:48 +00:00
"\nSeed(0); Non-repeating.\n";
Seed(0);
for (i=0;i<5;i++)
"%d: %d\n",i,RandI16;
2020-02-15 20:01:48 +00:00
Seed; //Default should be kept to zero.
2020-02-15 20:01:48 +00:00
}
RandDemo;