vendredi 9 décembre 2016

Generate random floats a in discontinuous range

I am looking to generate random floats to populate a virtual reality world with objects, using the floats to define the locations of the objects. Right now it is easy to uniformly fill a "box" with objects using random.uniform call.

import random

#generate random floating coordinates
for z in range(1000):
    x = random.uniform(-1,1)
    y = random.uniform(-1,1)
    z = random.uniform(-1,1)
    #shape = vizshape.addSphere() commented out because this is an uncommon module for VR but I wanted to show how floats are being used
    #shape.setPosition([x,y,z])

What I would like to do is pass in arguments to random.uniform() that specify more than 1 range to generate floats in, something like:

x = random.uniform([-1,1],[2,3])

Of course this will cause errors but I am looking for a way to get floats in multiple, size-varying, discontinuous ranges. I'd like to do it without writing another check to see if the generated floats are within my desired ranges and then deciding to keep or throw away. Any ideas?




Aucun commentaire:

Enregistrer un commentaire