Esmail wrote:
> Hi,
>
> random.random() will generate a random value in the range [0, 1).
>
> Is there an easy way to generate random values in the range [0, 1]?
> I.e., including 1?
>
> [...]
Here are three recipes, each more pedantic than the last. They all
assume that Python floats are IEE
Here's an example of a problem that I've recently come up against for
the umpteenth time. It's not difficult to solve, but my previous
solutions have never seemed quite right, so I'm writing to ask whether
others have encountered this problem, and if so what solutions they've
come up with.
Suppos
On Dec 6, 7:20 pm, Grant Edwards <[EMAIL PROTECTED]> wrote:
> It's a little less obtuse if you spell it this way:
>
> def flipbits(x):
> """reverse bits in a byte"""
> x1 = x << 4 | x >> 4
> x2 = (x1 & 0x33) << 2 | (x1 & 0xcc) >> 2
> return (x2 & 0x55) << 1 | (x2 & 0xaa) >> 1
>
G
On Dec 6, 6:01 pm, "Craig" <[EMAIL PROTECTED]> wrote:
> Thanks so much for the response. I have an array of individual bytes
> which will eventually make up a binary bitmap image that is loaded onto
> an LCD screen (1 = black dot, 0 = white dot). At the moment each byte
> is reversed to what it s
On Nov 29, 6:59 pm, "Steve Bergman" <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > > BTW, can this code be made any more efficient?
>
> > I'm not sure, but the following code takes around 6 seconds on my
> > 1.2Ghz iBook. How does it run on your machine?
>
> Hmm. Come to think of it,
> BTW, can this code be made any more efficient?
I'm not sure, but the following code takes around 6 seconds on my
1.2Ghz iBook. How does it run on your machine?
def smallPrimes(n):
"""Given an integer n, compute a list of the primes < n"""
if n <= 2:
return []
sieve = range
swisscheese wrote:
>
> r=range(2,99)
> m=[x*y for x in r for y in r]
> [x for x in r if not x in m]
How about:
[2]+[x for x in range(1,99) if 2**x%x==2]
Mark
--
http://mail.python.org/mailman/listinfo/python-list