I have a model like so:
class RunnerStat(models.Model):
id_card= models.CharField(max_length=32)
miles = models.PositiveSmallIntegerField()
last_modified = models.DateField(auto_now=True)
I want to create several RunnerStat instances with random miles values that average up to a specific number.
I know this might involve some statistics (distribution, etc.). Does anyone have any pointers? Or done something similar and could share some code?
Example: Create 100 RunnerStat objects with random miles values that average out to 10.
If the average has to be around the the given number but not exactly it you can use the
random.gauss(mu, sigma)from the random module. This will create a more natural random set of of values that have a mean (average) around the given value formuwith a standard deviation ofsigma. The more runners you create the closer the mean will get to the desired value.If you need the average to be the exact number then you could always create a runner (or more reasonably a few runners) that counter balance what ever your current difference from the mean is.