- Joined
- Nov 20, 2013
- Messages
- 5,652 (1.35/day)
- Location
- Kyiv, Ukraine
System Name | WS#1337 |
---|---|
Processor | Ryzen 7 5700X3D |
Motherboard | ASUS X570-PLUS TUF Gaming |
Cooling | Xigmatek Scylla 240mm AIO |
Memory | 64GB DDR4-3600(4x16) |
Video Card(s) | MSI RTX 3070 Gaming X Trio |
Storage | ADATA Legend 2TB |
Display(s) | Samsung Viewfinity Ultra S6 (34" UW) |
Case | ghetto CM Cosmos RC-1000 |
Audio Device(s) | ALC1220 |
Power Supply | SeaSonic SSR-550FX (80+ GOLD) |
Mouse | Logitech G603 |
Keyboard | Modecom Volcano Blade (Kailh choc LP) |
VR HMD | Google dreamview headset(aka fancy cardboard) |
Software | Windows 11, Ubuntu 24.04 LTS |
I'm using Code::Blocks to write the code and rand() function always return 0.
I tried to plant the seed with srand(time(NULL)), srand(opm_get_wtime()) and at least 10 different other methods, but it does not work...
Does anybody know how to fix this?
The general outline of my code looks like this:
I tried to plant the seed with srand(time(NULL)), srand(opm_get_wtime()) and at least 10 different other methods, but it does not work...
Does anybody know how to fix this?
The general outline of my code looks like this:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#include <time.h>
int main()
{
int toss;
int number_in_circle = 0;
int number_of_tosses = 10;
double distance_squared;
double x;
double y;
srand(time(NULL));
for (toss=0;toss<number_of_tosses;toss++)
{
x = rand()/RAND_MAX - 1;
y = rand()/RAND_MAX - 1;
printf("x=%f",x);
printf("y=%f\r\n",y);
distance_squared = x * x + y * y ;
if ( distance_squared <= 1) number_in_circle++;
}
int pi_estimate = 4*number_in_circle /((double) number_of_tosses );
printf("Pi estimate: %d",pi_estimate);
return 0;
}