Where should I report this bug with <cstdlib> header [C++]? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Where should I report this bug with <cstdlib> header [C++]?

I have found a bug. When my "Random Decimal Generator" code is run through the gcc compiler, it does exactly what it's supposed to do - generate 256 doubles from 0.0 to 1.0. However, the sololearn compiler instead generates 256 gradually increasing values that are definitely NOT random. Where can I report this?

17th Jun 2018, 8:21 PM
Drew Seedot
Drew Seedot - avatar
1 Answer
+ 3
This is your code. https://code.sololearn.com/cL8VNzOs7ni1/?ref=app The reason why is because you keep seeding it with i for each iteration, which is not how you should seed the RNG for a program. Furthermore, the value of i is the same for each instance of execution of your program, of course it wouldn't be random. This has nothing to do with the headers. This, on the other hand, works just fine. #include <cstdlib> #include <cstdio> #include <climits> #include <ctime> using namespace std; #define ARR_SIZE 256 int main() { srand(time(0)); for (int i = 0; i < ARR_SIZE; i++) { printf("%f,\n", double (rand()) / double (RAND_MAX)); } }
18th Jun 2018, 3:14 AM
Hatsy Rei
Hatsy Rei - avatar