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><code>randint</code> takes two arguments: a lower and upper (inclusive) bound for the generated number. Your code will generate a number between 1 and 1000 (inclusive), which could be anywhere from 1 to 4 digits.</p>

<p>This will generate a number between 1 and 9999999999:</p>

<pre><code>&gt;&gt;&gt; n = random.randint(1, 9999999999)
</code></pre>

<p>You will then want to pad it with zero's and make it a string, in case it is less than 10 digits:</p>

<pre><code>&gt;&gt;&gt; filename = str(n).zfill(10)
</code></pre>

<p>You can then open this and write to it:</p>

<pre><code>with open(filename + '.txt', 'w') as f:
    # do stuff
    pass
</code></pre>

python python-3.x random