Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ec2simulation
- import rand "math/rand"
- type Simulation struct {
- max_instances uint // Maximum number of instances that may be started
- clock *Clock // Simulation virtual time, starts at 0 and incremented by Tick()
- rand *rand.Rand // Psuedo-random number generator. Seed may be fixed to allow deterministic results
- chunks []*Chunk
- }
- func NewSimulation(max_instances uint) *Simulation {
- sim := &Simulation{max_instances: max_instances}
- sim.clock = NewClock()
- sim.rand = rand.New(rand.NewSource(0))
- return sim
- }
- func (sim *Simulation) Run(duration uint) {
- for i := uint(0); i < duration; i++ {
- sim.step()
- }
- }
- func (sim *Simulation) AddChunks(count uint, duration_mean uint, duration_stddev float64) {
- for i := uint(0); i < count; i++ {
- // Create chunk with random duration specified by |duration_mean| and |duration_stddev|
- duration := uint(rand.NormFloat64() * duration_stddev + float64(duration_mean))
- sim.chunks = append(sim.chunks, NewChunk(sim.clock, duration))
- }
- }
- func (sim *Simulation) step() {
- sim.clock.Tick()
- }
Add Comment
Please, Sign In to add comment