Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- #include <time.h>
- int main(int argc, char* argv[]){
- clock_t start = clock();
- int i=0;
- float xn =1.0;
- int a =573432;
- float n =2e31;
- long points=1e5;
- float* numsx =malloc(points * sizeof(float));//allocate mem so larger arrays can be used
- float* numsy =malloc(points * sizeof(float));
- float xn1=0.0;
- int arrayx=0;
- int arrayy=0;
- int y=1;
- int j=0;
- for (i=0; i< (2*points +1); i++){
- xn1=fmod((a*xn),n);//eqn whitch gens the rendom nums
- if (y==1){
- numsx[arrayx]=xn1;//adds to x array and y array alternativly
- arrayx++;
- }
- if (y==-1){
- numsy[arrayy]=xn1;
- arrayy++;
- }
- y= -y;
- xn =xn1;
- }
- for(j=0; j < 500; j++){
- printf("%f",numsx[j]);
- }
- clock_t finish =clock();
- double timeused;
- timeused=(finish-start)/CLOCKS_PER_SEC;//time taken to calc
- printf("\n%lf\n", timeused);
- FILE *file;
- file =fopen("randomnums.dat", "w");
- if (file == NULL) {
- printf("I couldn't open results.dat for writing.\n");//fails if file cant be opened
- exit(0);
- }
- for(i=0; i< (points/2); i++){
- fprintf(file, "%f %f\n", numsx[i], numsy[i]);//wirtes to file in format: x space y
- }
- fclose(file);//must remember to close file and relese the memory from malloc
- free(numsy);
- free(numsx);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement