All pastes #1037504 Raw Edit

Mine

public text v1 · immutable
#1037504 ·published 2008-06-03 03:58 UTC
rendered paste body
#!/usr/bin/python

import Planet
import random

def createUniverse(universeSize):
	'''CreateUniverse will create random planets with names'''
	randomPositions((0,9), (0,9), (0,9), universeSize)
	#Just a temp list, will be user defined later
	planetNames = [	'Mars',
			'Jupiter',
			'Saturn',
			'Pluto',
			'Venus',
			'Mercury',
			'Neptune',
			'Uranus',
			'Earth' ]
	#Name = random.choice(PlanetNames)
	#Names.Remove(Name)
	Name = planetNames.pop(random.randrange(len(planetNames)))
	planets = [Planet.Planet(Name,randomPositions[0]) for x in xrange(universeSize)]
	
	return planets

def randomPositions((x_min, x_max), (y_min, y_max), (z_min, z_max), count):
    x_range, y_range = x_max - x_min + 1, y_max - y_min + 1
    limit = x_range * y_range * (z_max - z_min + 1)
    randomLocations = []
    for n in random.sample(xrange(limit), count):
        n, x = divmod(n, x_range)
        z, y = divmod(n, y_range)
        randomLocations.append((x + x_min, y + y_min, z + z_min))
    return randomLocations


if __name__=='__main__':
	createUniverse(5)