Yes - of course it does. Without "random" in front choice is an attribute with no object. I didn't actually do it, but thats what would happen - "choice is not defined blahblah" Is that the same as saying its not a "global namespace"?
I'd have to consult a reference book to be 100% sure. I'm not certain how a pure object oriented language treats namespaces compared to a procedural language (ie, C++ is both procedural and OOP - I need to do a review
For example, In C++ you explicitly state your namespaces - in 99% of cases students do this by adding a line 'using namespace std;' (std = standard) near the top of their file, which is frowned upon with most real projects. By doing this they don't have to put the namespace std in front of functions defined in std.
cout << "hello" << endl; //prints hello
std::cout << "hello" << std::endl; //prints hello
Now say you have a special cout function that prints ascii numbers instead of the letters to the console. You can define a namespace in your file called Manta and do this....
Manta::cout << "hello" << std::endl; //prints 90 88 96 96 99 (just guessing the ascii values)
In practice, namespaces are used in procedural languages to avoid name clashes. When a project gets large enough, you start running out of good descriptive variable names, so it is better to create seperate namespaces and reuse these descriptive names instead of resorting to complicated naming gyrations.
"It looks to me like random might be a static class with static methods, hence, no need to instantiate anything. "
Yes - a very good way to say it. How come the texts don't say that?
Got me - maybe I should write a book.
This is just what I think is happening... I'd have to consult python.org to be sure.
Do Java and C++ have Modules? Please describe or give a definition to me for that.
No. Java has the following....
packages - groups of related classes form a package.
example: javax.swing is the package for the swing classes
example: java.lang contains the core classes of the Java language
classes - you know what these are....
Math is a class containing fields and methods related to math
JButton is a class for instantiating a button in swing
And you can create your own packages.... there are a few rules for doing this.
In C++, which supports both procedural and OOP, the main library is called the STL - standard template library, which uses the namespace std like I showed you above. Instead of using a package, C++ has a keyword called friend - imo, friends are the most unfriendly thing I've seen in any language and I much prefer Java's use of packages.
My language class didn't cover Python - C++, Java, Ada, LISP, Fortran, Prolog, Cobol and some others - here is what one of the tutorials says...
You can use a module to organize a number of Python definitions in a single file. <snip> A package is a way to organize a number of modules together as a unit. Python packages can also contain other packages.
So Python has both modules and packages where it looks like a module is a related to group of classes and functions, and a package is a related group of modules and other packages. Here is a link that I think will explain it in detail.... I plan on reading it later tonight.