C language random function rand ()

Random function rand () produced is between 0 ~ RAND_MAX an integer

Symbolic constants RAND_MAX in the header file stdlib.h need to include stdlib.h the time definition, the use of the function

The control range for generating random numbers
1. Use remainder operation rabd ()% b will vary rand () function to generate a random number [0, b-1] between
2. Use the rand ()% b + a random master translated to the range between [a, a + b-1]

  eg.生成1~100之间的随机数
    magic=rand() % 100 + 1;
Released seven original articles · won praise 3 · Views 475

Guess you like

Origin blog.csdn.net/qq_39600733/article/details/81433359