Thread: Random generation of a picturebox control....

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Random number generators on finite state machines (i.e. computers) aren't random at all. Essentially your C compiler includes or builds at runtime a "book" of pseudo-random numbers. Whenever you ask for a random number, the computer refers to this book at a specific position, reads a number and then increments the position. The "specific position" this process starts from is what is set by srand(), literally "seeding the random number generator".

    The statement:-
    Code:
    //correct form
    srand((unsigned int)time(NULL));
    Randomizes this position using the current system time, to give a further illusion of randomness.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    131
    I just wanted to say thanks again for the help, I think I have figured it out. I ditched the rand() function and went with the System::Random class. Hear is what I came up with.....
    Code:
    private: System::Void newGame_Menu(System::Object *  sender, System::EventArgs *  e)
    		{	int Next( int maxValue);
    			System::Random* m_Random = new System::Random();
    			int newx = ship->Location.X; 
    			int newy = ship->Location.Y; 
    			Point newloc = Point(m_Random->Next(456),408); 
    			ship->Location = newloc; 
    		}
    At first I could not figure out how to overload the next method to set a range but then it clicked.

    Thanks

    Chad

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rapid random number generation problem
    By Newton in forum C Programming
    Replies: 17
    Last Post: 09-19-2008, 02:08 PM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  3. non repeating random number generation?
    By gencor45 in forum C# Programming
    Replies: 1
    Last Post: 02-08-2005, 05:23 PM
  4. fast random number generation
    By Heraclitus in forum C Programming
    Replies: 4
    Last Post: 02-09-2003, 07:48 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM