Quantcast
Viewing all articles
Browse latest Browse all 40524

Seeding a random number

I am trying to create a random number generator with a random seed. The problem I am having is that I am trying to define my randomized variable as a global variable so I have put the rand statement in the first line.

This seems to always error out.

So I tried to put the srand(time(NULL)) statement under main() under the main.cpp file and then my ofApp.cpp can not find the srand statement and again rand does not have a random seed.

From what I can tell I can only globally define variables because when I try to define anything else code::blocks complains that I do not have a main() statement preceding it.

I think this may be confusing so here is the code I am trying to use

include "ofApp.h"

srand (time(NULL));
int start = rand()%500+30;

int xCord = start;

Does what I am asking make any sense?


Viewing all articles
Browse latest Browse all 40524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>