المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : What's the best method for calling a random function?



C# Programming
04-12-2009, 03:54 AM
I am trying to find out the best practice for calling one function out a set at random. I am using this to establish a random event in a video game.

For instance, let's say over time a bunch of different things could happen to a plant over time. So, every 5 hours, a random thing happens to this plant (resulting in 1 of many functions being fired).

The current way I am thinking about this follows in this example:

A timer knows about a list of 100 plants. When the timer ticks, it is randomly decided that the InsectInfestation method will be fired and it will affect 30 plants.

Where is the best place to store these random event methods?
The plant? An interface to the plant?

What is the best method of firing one at random?
A delegate in the timer that queues up the methods contained in the 30 affected plants? If so, how do I call up these methods in an algorithm?

---------------
TyloCook