Question: I just started programming with python 2.7, and I have some trouble with my random generator for taking items from an outside .txt file, wondering if anyone could help me a little bit...

Basically Id like to take 100 random hits, and count them all up in the end, and print the summary for the strings. I hope it makes sense!

I know this question has been answered before, but the answeres havent helped me.

So, my txt file contains a bunch of strings, separated with commas.
This is what my code looks like:

```
import random

fname = raw_input("Enter filename: ")
infile = open(fname,'r')
data = infile.readlines()

for i in range(100):
   print(random.uniform("Car_types.txt"))

```

Thanks for your help in advance!

Answer: 
This is probably what you're looking for:

```
import random

fname = raw_input("Enter filename: ")
# With statements are better as they explicitly close the file
with open(fname,'r') as infile:
    data = infile.read().split(",")  # Split the strings with commas as you said

for i in range(100):
   print(random.choice(data))  # This will randomly choose one of the strings

```
If you don't want to potentially get the same values, take a *sample* after splitting the data on commas:

```
fname = raw_input("Enter filename: ")
with  open(fname) as f:
    for r in random.sample(f.read().split(), 100):
        print(r)

```

You are opening the file, calling readlines and then never using the content at all, `random.uniform("Car_types.txt"))` is acting on the literal string `"Car_types.txt"`, you need to use the actual file content.