0
What does Srand does? Explain with example
3 ответов
+ 1
srand generates your random seed. typically you use srand (time (NULL)) Which will seed it to the current time of the cpu to generate a new unique number
0
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main() {
srand(time(NULL));
int x = rand ()% 10 + 1;//generates a number from 0->9 then adds 1
return 0;
}
- 2
<?php
//seed with micro second
Function make_seed()
{List($usec, $sec) =explode(' '
, microtime());
return $sec + $usec* 1000000;
}
Srand(make_seed());
$randval=rand();
? >