Random Limits

I am trying to have a text render in random positions.
I tried this:

self.Letter_1 = DirectLabel(text = “H”, text_scale = (0.35), text_font = self.fontBullpen, text_roll = random()*15-30, scale = 0.5, pos = (0, random()*-5+5, 0), text_fg = (0.5,1,0,1), text_shadow = (0,0,0,5), text_align = TextNode.ALeft, relief = 3, frameColor=(0, 0.5, 0, 0))

but it only rotates to the right all the time. It never rotates left.
How can I make it rotate to the left at times? I am not sure if my code is right.

(Sorry about not setting the code as a code. It’s not working when I bold the text)


The range of random.random() is [0,1), so random()*15-30 will range from -30 to -15: always negative. To have it split evenly, do random()*30 - 15 (range will then be -15 to 15).

(also, although it might be on purpose, your pos will return values from -5 to 0)


I was not sure on the pos either.

An extra thanks for the simple explanation you give. It’s so helpful to have things explaiined as to how they work. Thanks