snipt

Ctrl+h for KB shortcuts

Python

Simple generation of random string in Python

1
2
3
4
import string
import random

print "".join(random.sample(string.letters+string.digits, 8))
https://snipt.net/embed/ac145bb5129e46f730fa7009e98abfb5/
/raw/ac145bb5129e46f730fa7009e98abfb5/
ac145bb5129e46f730fa7009e98abfb5
python
Python
4
2019-07-20T14:28:09
True
False
False
/api/public/snipt/6463/
simple-generation-of-random-string-in-python
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kn">import</span> <span class="nn">string</span> </span><span id="L-2"><a name="L-2"></a><span class="kn">import</span> <span class="nn">random</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="k">print</span> <span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">sample</span><span class="p">(</span><span class="n">string</span><span class="o">.</span><span class="n">letters</span><span class="o">+</span><span class="n">string</span><span class="o">.</span><span class="n">digits</span><span class="p">,</span> <span class="mi">8</span><span class="p">))</span> </span></pre></div> </td></tr></table>
python, random, strings