Generate random number in a range [0, n) in C?

后端 未结 4 970
小蘑菇
小蘑菇 2021-01-26 01:13

Looking to make a really simple random number generator method in C. The numbers should be between 0 and 24 and can be for example 14.5f.

Any help would be great, thanks

4条回答
  •  抹茶落季
    2021-01-26 01:48

    You can use C's built in random number generator to get an integer between 0 and 30 thousand something like this:

    `srand(time(NULL));
        int x= rand();`

    You would just need to do some division to get a decimal number instead of and integer.

提交回复
热议问题