#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    146
    Rep Power
    12

    Random Number Generating (Whole numbers)


    Hi all,

    I am using the following code and am getting errors thrown at me, but I can't understand why?

    Code:
    from random import Random, random

    num = random.randint(10,20)
    print num

    End of code.

    The error is saying that I can't import name random? So obviously the error lies on line 1.

    Can anyone see what might be causing this error?

    Cheers
    Tryst
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    146
    Rep Power
    12
    It seems that it was my file name that was causing the problem (random.py).

    I am still getting an error, though. Through the same code as in the previous post, I am getting the folowing error message...

    'function' object has no attribute 'randint'

    Anyone see where I am going wrong?

    Cheers
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    Try this instead:
    Code:
    import random
    num = random.randint(10, 20)
    print num
    or this:
    Code:
    from random import randint
    num = randint(10, 20)
    print num
    Last edited by Scorpions4ever; February 13th, 2004 at 10:35 AM.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    146
    Rep Power
    12
    Cheers, the second section of code works fine.

    Tryst
    Tryst

IMN logo majestic logo threadwatch logo seochat tools logo