How do you use the random.randint function for variables?

How do you do this with out it resulting in a error?

import random

apple=8
carrot=1

banana=random.randint(carrot,apple)

:spin:

I’m guessing you are getting the “No module named random” error. If so, you need to install Python. Your code works well with Python installed, both in command line and as Blender script.

The explanation is: Blender Python does not have its own random library. The random library is one of Python standard libraries. You only get it once you installed the standard Python distribution on your machine.

If you don’t want to install Python, you can use the Blender Mathutils library, it has a Rand function to return a random number between the low and high values:

from Blender import Mathutils
apple=8
carrot=1
banana=int(Mathutils.Rand(carrot,apple))

@ Da Krazy Jak - Frankly, I tested your supplied code “as is” in Blender 2.49b and there’s been NO error in the result(s)! I guess it will run OK in 2.5x too cause it is a rather general code (I havent tested this yet).

May be you need to supply more info about your problem - which Blender version you use, if Python is installed properly, add CODE-/CODE tags to your supplied code, publich a copy of console screen with the error message you receive…

Regards,

Thanks SnifiX your right that did work.