SpicyClubSauce
SpicyClubSauce

Reputation: 4276

Generating random sample with random.random in python

I'd like to generate a sample size of 100 random numbers between 0 and 1 using the random.random function.

import random
sample = [random.random for x in range(100)]

For instance, while print(len(sample)) gives me 100, print(sample[1]) returns just a reference to the random object() instead of the actual random number, which is what I want.

Why is this not working for me?

Probably basic, but I couldn't find an answer.

Upvotes: 2

Views: 171

Answers (1)

Padraic Cunningham
Padraic Cunningham

Reputation: 180522

You are not calling the method:

[random.random() for x in range(100)]
              ^^

Upvotes: 5

Related Questions