{"id":1111280,"date":"2025-01-08T17:27:41","date_gmt":"2025-01-08T09:27:41","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1111280.html"},"modified":"2025-01-08T17:27:44","modified_gmt":"2025-01-08T09:27:44","slug":"python%e5%a6%82%e4%bd%95%e7%94%9f%e6%88%90%e5%87%a0%e5%88%b0%e5%87%a0%e7%9a%84%e9%9a%8f%e6%9c%ba%e5%ba%8f%e5%88%97","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1111280.html","title":{"rendered":"Python\u5982\u4f55\u751f\u6210\u51e0\u5230\u51e0\u7684\u968f\u673a\u5e8f\u5217"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25073815\/871f1f78-6e57-4c09-87f6-d8e34c9fa3aa.webp\" alt=\"Python\u5982\u4f55\u751f\u6210\u51e0\u5230\u51e0\u7684\u968f\u673a\u5e8f\u5217\" \/><\/p>\n<p><p> <strong>Python\u751f\u6210\u51e0\u5230\u51e0\u7684\u968f\u673a\u5e8f\u5217\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528random\u6a21\u5757\u4e2d\u7684randrange\u3001randint\u3001sample\u7b49\u51fd\u6570\u6765\u5b9e\u73b0\u3001\u53ef\u4ee5\u751f\u6210\u6709\u5e8f\u6216\u65e0\u5e8f\u7684\u968f\u673a\u5e8f\u5217<\/strong>\u3002\u5176\u4e2d\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528random\u6a21\u5757\u7684sample\u51fd\u6570\u6765\u751f\u6210\u4e0d\u91cd\u590d\u7684\u968f\u673a\u5e8f\u5217\u3002\u4e0b\u9762\u6211\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u8981\u751f\u6210\u4e00\u4e2a\u51e0\u5230\u51e0\u7684\u968f\u673a\u5e8f\u5217\uff0c\u9996\u5148\u9700\u8981\u660e\u786e\u5e8f\u5217\u7684\u8303\u56f4\u548c\u662f\u5426\u5141\u8bb8\u91cd\u590d\u3002\u5982\u679c\u9700\u8981\u751f\u6210\u4e00\u4e2a\u4e0d\u91cd\u590d\u7684\u968f\u673a\u5e8f\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528random.sample()\u51fd\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u5141\u8bb8\u6211\u4eec\u4ece\u4e00\u4e2a\u6307\u5b9a\u8303\u56f4\u5185\u7684\u5217\u8868\u4e2d\u968f\u673a\u9009\u62e9\u6307\u5b9a\u6570\u91cf\u7684\u5143\u7d20\uff0c\u5e76\u4ee5\u5217\u8868\u5f62\u5f0f\u8fd4\u56de\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5bfc\u5165random\u6a21\u5757<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u8981\u751f\u6210\u968f\u673a\u5e8f\u5217\uff0c\u9700\u8981\u5bfc\u5165random\u6a21\u5757\u3002random\u6a21\u5757\u5305\u542b\u4e86\u751f\u6210\u968f\u673a\u6570\u548c\u968f\u673a\u9009\u62e9\u5143\u7d20\u7684\u5404\u79cd\u51fd\u6570\u3002\u4ee5\u4e0b\u662f\u5bfc\u5165random\u6a21\u5757\u7684\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528randrange\u751f\u6210\u968f\u673a\u6570<\/h3>\n<\/p>\n<p><p>random.randrange()\u51fd\u6570\u53ef\u4ee5\u7528\u6765\u751f\u6210\u6307\u5b9a\u8303\u56f4\u5185\u7684\u968f\u673a\u6574\u6570\u3002\u5b83\u6709\u4e09\u4e2a\u53c2\u6570\uff1astart\u3001stop\u548cstep\u3002start\u662f\u8d77\u59cb\u503c\uff08\u5305\u542b\uff09\uff0cstop\u662f\u7ed3\u675f\u503c\uff08\u4e0d\u5305\u542b\uff09\uff0cstep\u662f\u6b65\u957f\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528randrange()\u751f\u6210\u968f\u673a\u6570\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<h2><strong>\u751f\u62105\u523015\u4e4b\u95f4\u7684\u968f\u673a\u6570\uff08\u4e0d\u5305\u542b15\uff09<\/strong><\/h2>\n<p>random_number = random.randrange(5, 15)<\/p>\n<p>print(random_number)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u751f\u6210\u5355\u4e2a\u968f\u673a\u6570\u3002\u5982\u679c\u9700\u8981\u751f\u6210\u591a\u4e2a\u968f\u673a\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528randint\u751f\u6210\u968f\u673a\u6570<\/h3>\n<\/p>\n<p><p>random.randint()\u51fd\u6570\u4e0erandrange()\u7c7b\u4f3c\uff0c\u4f46\u5b83\u751f\u6210\u7684\u968f\u673a\u6570\u5305\u542b\u7ed3\u675f\u503c\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528randint()\u751f\u6210\u968f\u673a\u6570\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<h2><strong>\u751f\u62105\u523015\u4e4b\u95f4\u7684\u968f\u673a\u6570\uff08\u5305\u542b15\uff09<\/strong><\/h2>\n<p>random_number = random.randint(5, 15)<\/p>\n<p>print(random_number)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u4e5f\u9002\u7528\u4e8e\u751f\u6210\u5355\u4e2a\u968f\u673a\u6570\u3002\u5982\u679c\u9700\u8981\u751f\u6210\u591a\u4e2a\u968f\u673a\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528sample\u751f\u6210\u968f\u673a\u5e8f\u5217<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u751f\u6210\u4e00\u4e2a\u4e0d\u91cd\u590d\u7684\u968f\u673a\u5e8f\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528random.sample()\u51fd\u6570\u3002\u8fd9\u4e2a\u51fd\u6570\u4ece\u6307\u5b9a\u8303\u56f4\u5185\u7684\u5217\u8868\u4e2d\u968f\u673a\u9009\u62e9\u6307\u5b9a\u6570\u91cf\u7684\u5143\u7d20\uff0c\u5e76\u4ee5\u5217\u8868\u5f62\u5f0f\u8fd4\u56de\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528sample()\u751f\u6210\u968f\u673a\u5e8f\u5217\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<h2><strong>\u751f\u62105\u523015\u4e4b\u95f4\u7684\u968f\u673a\u5e8f\u5217\uff08\u4e0d\u5305\u542b15\uff09\uff0c\u5e8f\u5217\u957f\u5ea6\u4e3a5<\/strong><\/h2>\n<p>random_sequence = random.sample(range(5, 15), 5)<\/p>\n<p>print(random_sequence)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u786e\u4fdd\u751f\u6210\u7684\u968f\u673a\u5e8f\u5217\u4e0d\u5305\u542b\u91cd\u590d\u5143\u7d20\u3002\u5982\u679c\u9700\u8981\u751f\u6210\u5305\u542b\u91cd\u590d\u5143\u7d20\u7684\u968f\u673a\u5e8f\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528random.choices()\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u751f\u6210\u5305\u542b\u91cd\u590d\u5143\u7d20\u7684\u968f\u673a\u5e8f\u5217<\/h3>\n<\/p>\n<p><p>random.choices()\u51fd\u6570\u5141\u8bb8\u751f\u6210\u5305\u542b\u91cd\u590d\u5143\u7d20\u7684\u968f\u673a\u5e8f\u5217\u3002\u5b83\u6709\u4e24\u4e2a\u4e3b\u8981\u53c2\u6570\uff1apopulation\u548ck\u3002population\u662f\u751f\u6210\u968f\u673a\u5e8f\u5217\u7684\u8303\u56f4\uff0ck\u662f\u968f\u673a\u5e8f\u5217\u7684\u957f\u5ea6\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528choices()\u751f\u6210\u5305\u542b\u91cd\u590d\u5143\u7d20\u7684\u968f\u673a\u5e8f\u5217\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<h2><strong>\u751f\u62105\u523015\u4e4b\u95f4\u7684\u968f\u673a\u5e8f\u5217\uff08\u4e0d\u5305\u542b15\uff09\uff0c\u5e8f\u5217\u957f\u5ea6\u4e3a5\uff0c\u5141\u8bb8\u91cd\u590d\u5143\u7d20<\/strong><\/h2>\n<p>random_sequence = random.choices(range(5, 15), k=5)<\/p>\n<p>print(random_sequence)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u751f\u6210\u6709\u5e8f\u7684\u968f\u673a\u5e8f\u5217<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u751f\u6210\u4e00\u4e2a\u6709\u5e8f\u7684\u968f\u673a\u5e8f\u5217\uff0c\u53ef\u4ee5\u5148\u751f\u6210\u4e00\u4e2a\u968f\u673a\u5e8f\u5217\uff0c\u7136\u540e\u5bf9\u5176\u8fdb\u884c\u6392\u5e8f\u3002\u4ee5\u4e0b\u662f\u751f\u6210\u6709\u5e8f\u968f\u673a\u5e8f\u5217\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<h2><strong>\u751f\u62105\u523015\u4e4b\u95f4\u7684\u968f\u673a\u5e8f\u5217\uff08\u4e0d\u5305\u542b15\uff09\uff0c\u5e8f\u5217\u957f\u5ea6\u4e3a5<\/strong><\/h2>\n<p>random_sequence = random.sample(range(5, 15), 5)<\/p>\n<h2><strong>\u5bf9\u968f\u673a\u5e8f\u5217\u8fdb\u884c\u6392\u5e8f<\/strong><\/h2>\n<p>sorted_sequence = sorted(random_sequence)<\/p>\n<p>print(sorted_sequence)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u751f\u6210\u6307\u5b9a\u8303\u56f4\u5185\u7684\u6d6e\u70b9\u6570\u968f\u673a\u5e8f\u5217<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u751f\u6210\u6307\u5b9a\u8303\u56f4\u5185\u7684\u6d6e\u70b9\u6570\u968f\u673a\u5e8f\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528random.uniform()\u51fd\u6570\u3002\u4ee5\u4e0b\u662f\u751f\u6210\u6d6e\u70b9\u6570\u968f\u673a\u5e8f\u5217\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<h2><strong>\u751f\u62105.0\u523015.0\u4e4b\u95f4\u7684\u968f\u673a\u6d6e\u70b9\u6570<\/strong><\/h2>\n<p>random_float = random.uniform(5.0, 15.0)<\/p>\n<p>print(random_float)<\/p>\n<h2><strong>\u751f\u62105\u4e2a5.0\u523015.0\u4e4b\u95f4\u7684\u968f\u673a\u6d6e\u70b9\u6570<\/strong><\/h2>\n<p>random_floats = [random.uniform(5.0, 15.0) for _ in range(5)]<\/p>\n<p>print(random_floats)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516b\u3001\u751f\u6210\u5e03\u5c14\u503c\u968f\u673a\u5e8f\u5217<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u751f\u6210\u5e03\u5c14\u503c\u968f\u673a\u5e8f\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528random.choice()\u51fd\u6570\u3002\u4ee5\u4e0b\u662f\u751f\u6210\u5e03\u5c14\u503c\u968f\u673a\u5e8f\u5217\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<h2><strong>\u751f\u62105\u4e2a\u5e03\u5c14\u503c\u968f\u673a\u5e8f\u5217<\/strong><\/h2>\n<p>random_booleans = [random.choice([True, False]) for _ in range(5)]<\/p>\n<p>print(random_booleans)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e5d\u3001\u751f\u6210\u5b57\u7b26\u4e32\u968f\u673a\u5e8f\u5217<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u751f\u6210\u5b57\u7b26\u4e32\u968f\u673a\u5e8f\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528random.choices()\u51fd\u6570\u3002\u4ee5\u4e0b\u662f\u751f\u6210\u5b57\u7b26\u4e32\u968f\u673a\u5e8f\u5217\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p>import string<\/p>\n<h2><strong>\u751f\u6210\u5305\u542b\u5b57\u6bcd\u548c\u6570\u5b57\u7684\u968f\u673a\u5b57\u7b26\u4e32\uff0c\u957f\u5ea6\u4e3a10<\/strong><\/h2>\n<p>random_string = &#39;&#39;.join(random.choices(string.ascii_letters + string.digits, k=10))<\/p>\n<p>print(random_string)<\/p>\n<h2><strong>\u751f\u62105\u4e2a\u5305\u542b\u5b57\u6bcd\u548c\u6570\u5b57\u7684\u968f\u673a\u5b57\u7b26\u4e32\uff0c\u6bcf\u4e2a\u5b57\u7b26\u4e32\u957f\u5ea6\u4e3a10<\/strong><\/h2>\n<p>random_strings = [&#39;&#39;.join(random.choices(string.ascii_letters + string.digits, k=10)) for _ in range(5)]<\/p>\n<p>print(random_strings)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u3001\u7efc\u5408\u793a\u4f8b\uff1a\u751f\u6210\u6df7\u5408\u7c7b\u578b\u7684\u968f\u673a\u5e8f\u5217<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\u9700\u8981\u751f\u6210\u5305\u542b\u4e0d\u540c\u7c7b\u578b\u5143\u7d20\u7684\u968f\u673a\u5e8f\u5217\uff0c\u53ef\u4ee5\u5c06\u4e0a\u9762\u7684\u5404\u79cd\u65b9\u6cd5\u7ed3\u5408\u8d77\u6765\u3002\u4ee5\u4e0b\u662f\u751f\u6210\u5305\u542b\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5e03\u5c14\u503c\u548c\u5b57\u7b26\u4e32\u7684\u6df7\u5408\u7c7b\u578b\u968f\u673a\u5e8f\u5217\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p>import string<\/p>\n<p>def generate_random_sequence():<\/p>\n<p>    sequence = []<\/p>\n<p>    for _ in range(5):<\/p>\n<p>        sequence.append(random.randint(5, 15))<\/p>\n<p>        sequence.append(random.uniform(5.0, 15.0))<\/p>\n<p>        sequence.append(random.choice([True, False]))<\/p>\n<p>        sequence.append(&#39;&#39;.join(random.choices(string.ascii_letters + string.digits, k=5)))<\/p>\n<p>    return sequence<\/p>\n<p>random_sequence = generate_random_sequence()<\/p>\n<p>print(random_sequence)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u7ed3\u5408\u4e0d\u540c\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u751f\u6210\u5305\u542b\u5404\u79cd\u7c7b\u578b\u5143\u7d20\u7684\u968f\u673a\u5e8f\u5217\uff0c\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u968f\u673a\u6570\u751f\u6210\u51fd\u6570\uff0c\u901a\u8fc7\u5408\u7406\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\uff0c\u53ef\u4ee5\u751f\u6210\u5404\u79cd\u7c7b\u578b\u7684\u968f\u673a\u5e8f\u5217\u3002\u65e0\u8bba\u662f\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5e03\u5c14\u503c\u8fd8\u662f\u5b57\u7b26\u4e32\uff0c\u90fd\u53ef\u4ee5\u4f7f\u7528random\u6a21\u5757\u4e2d\u7684\u51fd\u6570\u751f\u6210\u3002\u5e0c\u671b\u672c\u6587\u7684\u8be6\u7ec6\u4ecb\u7ecd\u80fd\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\uff0c\u751f\u6210\u7b26\u5408\u81ea\u5df1\u9700\u6c42\u7684\u968f\u673a\u5e8f\u5217\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u751f\u6210\u6307\u5b9a\u8303\u56f4\u5185\u7684\u968f\u673a\u6574\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>random<\/code>\u6a21\u5757\u4e2d\u7684<code>randint()<\/code>\u51fd\u6570\u751f\u6210\u6307\u5b9a\u8303\u56f4\u5185\u7684\u968f\u673a\u6574\u6570\u3002\u8be5\u51fd\u6570\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570\uff0c\u5206\u522b\u662f\u751f\u6210\u968f\u673a\u6570\u7684\u4e0b\u9650\u548c\u4e0a\u9650\u3002\u4f8b\u5982\uff0c\u8981\u751f\u6210\u4e00\u4e2a\u57281\u523010\u4e4b\u95f4\u7684\u968f\u673a\u6574\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">import random\nrandom_number = random.randint(1, 10)\nprint(random_number)\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c\u6bcf\u6b21\u8fd0\u884c\u4ee3\u7801\u65f6\uff0c\u90fd\u4f1a\u5f97\u5230\u4e00\u4e2a\u65b0\u7684\u968f\u673a\u6574\u6570\u3002<\/p>\n<p><strong>\u5982\u4f55\u751f\u6210\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u968f\u673a\u6570\u7684\u5217\u8868\uff1f<\/strong><br \/>\u5982\u679c\u60a8\u5e0c\u671b\u751f\u6210\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u968f\u673a\u6570\u7684\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528<code>random.sample()<\/code>\u51fd\u6570\u6216\u8005\u7ed3\u5408\u5217\u8868\u63a8\u5bfc\u5f0f\u4e0e<code>random.randint()<\/code>\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u5c06\u751f\u6210\u4e00\u4e2a\u5305\u542b5\u4e2a\u57281\u5230100\u4e4b\u95f4\u7684\u968f\u673a\u6574\u6570\u7684\u5217\u8868\uff1a  <\/p>\n<pre><code class=\"language-python\">random_list = [random.randint(1, 100) for _ in range(5)]\nprint(random_list)\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u8fd4\u56de\u4e00\u4e2a\u5305\u542b5\u4e2a\u968f\u673a\u6574\u6570\u7684\u5217\u8868\uff0c\u6bcf\u4e2a\u6574\u6570\u90fd\u5728\u6307\u5b9a\u7684\u8303\u56f4\u5185\u3002<\/p>\n<p><strong>Python\u4e2d\u5982\u4f55\u786e\u4fdd\u968f\u673a\u6570\u7684\u552f\u4e00\u6027\uff1f<\/strong><br \/>\u4e3a\u4e86\u786e\u4fdd\u751f\u6210\u7684\u968f\u673a\u6570\u5728\u4e00\u4e2a\u8303\u56f4\u5185\u662f\u552f\u4e00\u7684\uff0c\u53ef\u4ee5\u4f7f\u7528<code>random.sample()<\/code>\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u4f1a\u4ece\u6307\u5b9a\u8303\u56f4\u5185\u968f\u673a\u9009\u62e9\u4e0d\u91cd\u590d\u7684\u6570\u503c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u751f\u621010\u4e2a\u57281\u523050\u4e4b\u95f4\u7684\u552f\u4e00\u968f\u673a\u6570\uff1a  <\/p>\n<pre><code class=\"language-python\">unique_random_numbers = random.sample(range(1, 51), 10)\nprint(unique_random_numbers)\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u4fdd\u8bc1\u4e86\u6bcf\u4e2a\u968f\u673a\u6570\u90fd\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\uff0c\u9002\u7528\u4e8e\u9700\u8981\u4e0d\u91cd\u590d\u6570\u5b57\u7684\u573a\u666f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u751f\u6210\u51e0\u5230\u51e0\u7684\u968f\u673a\u5e8f\u5217\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528random\u6a21\u5757\u4e2d\u7684randrange\u3001randint\u3001sampl [&hellip;]","protected":false},"author":3,"featured_media":1111290,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1111280"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1111280"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1111280\/revisions"}],"predecessor-version":[{"id":1111292,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1111280\/revisions\/1111292"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1111290"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1111280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1111280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1111280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}