Code that generates a random 10 digit filename and creates the file
<p>I tried using:</p>

<pre><code>import random
filenamemaker = random.randint(1,1000)
</code></pre>

<p>all help would be great thanks :)</p>

<p>The simplest way would be with <a href="https://docs.python.org/3/library/string.html#string.digits" rel="nofollow"><code>string.digits</code></a> and <a href="https://docs.python.org/3/library/random.html#random.sample" rel="nofollow"><code>random.sample</code></a>. You could also use the <a href="https://docs.python.org/3/reference/compound_stmts.html#with" rel="nofollow"><code>with</code></a> statement with an empty <a href="https://docs.python.org/3/reference/simple_stmts.html#grammar-token-pass_stmt" rel="nofollow"><code>pass</code></a> in it if don't plan on using the file and automatically want it closed:</p>

<pre><code>from string import digits
from random import sample 

with open("".join(sample(digits, 10)), 'w'): 
    pass
</code></pre>

<p>This is equivalent to:</p>

<pre><code>filename = "".join(sample(digits, 10)) 
f = open(filename, 'w')
f.close()
</code></pre>

<p>On consecutive calls, this generates filenames such as:</p>

<pre><code>3672945108  6298517034
</code></pre>

python python-3.x random