Page 1 of 1

Random module problems

Posted: Thu Jan 23, 2014 5:44 pm
by Sheila
I was trying to use some random module functions and something seems very wrong.
I ran a brief program to check the first bit before actually executing any random statements. and something wasn't right. Without going through the whole diagnosis, it seems that just doing the "import random" command the program prints out whatever it has previously printed before running the program. It even manages to do this after its been rebooted or turned off. It does it regardless of whether its being run from geany or a command line, or whether or not I write a new program.

If I put in
random.sample (1,2,3),1)
it says attribute doesn't exist
If I put in
random.random()
it says attribute not callable


Any clues, what is going on here or how I fix it?

Re: Random module problems

Posted: Thu Jan 23, 2014 7:13 pm
by elParaguayo
Have you got a file called random.py in your folder?

It sounds like you're importing that file rather than the standard python random module.

Re: Random module problems

Posted: Thu Jan 23, 2014 8:05 pm
by Sheila
Thank you a million times!
Not only have you solved the problem, you stopped me having a nervous breakdown and saved the health service loads of money.

I'd started off calling the program random.py, thought that might be the problem and changed it. But it didn't occur to me that the new program was calling the old one instead of a module. I'd sort of forgot the old one was still in the directory once I'd changed the name. One of those situations where you've tried so many things you forget what you've done.

Re: Random module problems

Posted: Thu Jan 23, 2014 8:42 pm
by elParaguayo
Great, glad it's working.

If it's any consolation, it's a mistake we've all made before!