你那个可以是可以,但是要记得先打开定时器0(TR0=1;)!
你那个是和时间相关的,而Keil自带的是和种子相关和时间无关的 不知道的都可以按f1去看帮助: rand Summary #include <stdlib.h>
int rand (void);
Description The rand function generates a pseudo-random number between 0 and 32767. Return Value The rand function returns a pseudo-random number. See Also srand
Example #include <stdlib.h> #include <stdio.h> /* for printf */
void tst_rand (void) { int i; int r;
for (i = 0; i < 10; i++) { printf ("I = %d, RAND = %d
", i, rand ()); } }
|