c++ - Random and Randomize Function -


how random , randomize functions work? please me!

#include<iostream.h> #include<stdlib.h> const int low = 15; void main() {     randomize();       int point=10, number;       for(int i=1; i<=4; i++)       {      number = low + random(point);              cout<<number<<":";              point--;       } } 

what different outputs can predicted program? , how? explain. have got 4 options code 1) 24:23:22:21: 2) 24:25:23:21 3) 21:22:23:24 4) 22:23:21:24
, haven't got of these output, there must basic format or solve these types of programs. please help. have referred books telling these type of programs can't understand working of these type of programs.

short random(short num) macro uses rand() return random number between 0 , num-1.

randomize picks current time of system clock , uses seed (initial value) random number generator, output sequence of rand() different each time run program.

rand called pseudo random number generator (prng). can set seed void srand(unsigned seed).

try , you'll see same seed random sequence same each time run program.

this because algorithms can't create true randomness.

if want use prngs should use up-to-date generators std::default_random_engine. have larger periods , better statistical randomness properties.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -