I’m starting to sound like a Julia fan-boy. Any-who…I was rewriting in Julia a program I had previously written in Python, and I found this code from Python of where I wanted to generate a random month from 1-12
I ran it, and the months at first glance looked valid…and they were!
However it wasn’t until later that I realized there weren’t any month 12s
Actually, if memory serves, I don’t think I noticed until after I loaded the records into a SQLite database and started doing date calculations on the records
Why weren’t there any month 12s? Because the upper range DOES NOT INCLUDE THE UPPER RANGE!
It needed to be coded like so…
mn=random.randrange(1,13) # generate a random month from 1-12 in Python
On the other hand the code to generate random months in Julia…looks like this!
mn=rand(1:12) # generate a random month from 1-12 in Julia
It sounds like I’m bashing Python…I’m not…well maybe I am a little.
I have written many many useful Python programs, and if you code in it often, you probably remember these things. Now maybe there is another Python library or module that is more intutive, IDK, I’m sure I just used the 1st thing I saw to create random numbers.
However I often find Python quirky!
In my case, my brain…so far, clicks better with Julia, than Python…YMMV!
It’s as if Julia fixed many of the things that bugged me in Python. I know, fixed is the wrong word, because it’s not broke.