Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <math.h>
- const float RAND_MAX_F = RAND_MAX;
- // генерирует вещественное [0, 1]
- float get_rand() {
- return rand() / RAND_MAX_F;
- }
- // вещественное [min, max]
- float get_rand_range(const float min, const float max) {
- return get_rand() * (max - min) + min;
- }
- // целое [min, max]
- int get_rand_range_int(const int min, const int max) {
- return rand() % (max - min + 1) + min;
- }
- int main() {
- int i, r;
- srand(time(NULL));
- for (i = 0; i < 20; i++) {
- //r = ;
- printf("%d\n", get_rand_range_int(-5, 5));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement