null_reflections
Legendary Coder
I'm just wondering if what the folks on this stack is totally true, or maybe is outdated, and if it is true, then what they mean:
stackoverflow.com
The thread is over 13 years old, but when I test that particular way to establish a range of numbers, the results do appear totally random. However, this is a pretty small sample, i'd suppose you'd need to get a thousands of numbers this way before you knew for sure.
First block is my code, second block is the output:
Numbers in the 30's happened to appear several times in this, but that could easily just be chance.

How do I get a specific range of numbers from rand()?
srand(time(null)); printf("%d", rand()); Gives a high-range random number (0-32000ish), but I only need about 0-63 or 0-127, though I'm not sure how to go about it. Any help?
The thread is over 13 years old, but when I test that particular way to establish a range of numbers, the results do appear totally random. However, this is a pretty small sample, i'd suppose you'd need to get a thousands of numbers this way before you knew for sure.
First block is my code, second block is the output:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
int main (){
int i;
for ( i=0; i<30; i++ ) {
sleep(1);
srand(time(NULL));
int n = rand() % 100;
printf ("%d\n", n);
}
}
Code:
32
18
7
15
72
34
88
7
65
34
80
82
61
67
36
5
78
31
82
37
16
77
79
9
25
90
21
80
36
27
Numbers in the 30's happened to appear several times in this, but that could easily just be chance.