Random Odd Numbers
<p>My professor gave us our first assignment (Cs315), which involves dealing with some huge (odd) integers and determining if they are prime. I started to do this in c++ until I realized that even long long ints could not hold the numbers needed, so I was left with the choices of making a class of vectors in c++, or learning python in a few days. This simple piece of Python code is supposed to spit out an odd 256 bit random number. It spits out random numbers, both even and odd, and I don't know why, but my guess is a that it is a simple syntactical error that I am not seeing.</p>

<pre><code>import random
x = random.getrandbits(256)
if x % 2 == 0:
    x +  1
print x
</code></pre>

<p>You need to assign <code>x + 1</code> back to <code>x</code>. You can either do this like this: <code>x = x+1</code> or like this: <code>x += 1</code></p>

python python-3.x