I am attempting Monte Carlo integration for an assignment. This involves generating random numbers between -1 and 1 in both the x and y axis... I think I know how to generate random nmumbers between 0 and 1, but don't know how to change that to between -1 and 1. Any help would be appreciated and thanks in advance... Here's (a bit of) my code so far:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
double x,y;
int main(){
srand(time(NULL));
x=rand()/(double)(RAND_MAX);
y=rand()/(double)(RAND_MAX); /*HOW DO I MAKE THIS FROM -1 TO 1*/
return 0;
}
*I'm pretty sure I can tackle the rest of the problem myself once I know how to generate these negative random numbers so the code above is only a small section of the problem (the rest I intend to do myself)