{"id":1134648,"date":"2025-01-08T21:17:31","date_gmt":"2025-01-08T13:17:31","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1134648.html"},"modified":"2025-01-08T21:17:33","modified_gmt":"2025-01-08T13:17:33","slug":"python%e5%a6%82%e4%bd%95%e5%b0%861%e5%88%b0100%e9%9a%8f%e6%9c%ba%e6%94%be%e5%85%a5%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1134648.html","title":{"rendered":"python\u5982\u4f55\u5c061\u5230100\u968f\u673a\u653e\u5165\u6570\u7ec4"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25103527\/68ed917c-b73c-4e8b-8739-9aa03f304a67.webp\" alt=\"python\u5982\u4f55\u5c061\u5230100\u968f\u673a\u653e\u5165\u6570\u7ec4\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u5c061\u5230100\u7684\u6570\u5b57\u968f\u673a\u653e\u5165\u6570\u7ec4\u3002<\/strong> \u9996\u5148\uff0c\u53ef\u4ee5\u4f7f\u7528<code>random.sample()<\/code>\u65b9\u6cd5\uff0c\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5728\u4e0d\u91cd\u590d\u7684\u60c5\u51b5\u4e0b\u751f\u6210\u4e00\u4e2a\u5305\u542b1\u5230100\u7684\u968f\u673a\u6570\u7ec4\u3002\u53e6\u4e00\u4e2a\u5e38\u89c1\u7684\u65b9\u6cd5\u662f\u5148\u751f\u6210\u4e00\u4e2a\u6709\u5e8f\u7684\u6570\u7ec4\uff0c\u7136\u540e\u4f7f\u7528<code>random.shuffle()<\/code>\u65b9\u6cd5\u8fdb\u884c\u968f\u673a\u5316\u3002<strong>\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4f7f\u7528<code>random.sample()<\/code>\u65b9\u6cd5\u7684\u6b65\u9aa4\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>random.sample()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u975e\u5e38\u65b9\u4fbf\u5730\u751f\u6210\u4e00\u4e2a\u5305\u542b1\u5230100\u7684\u968f\u673a\u6570\u7ec4\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u65b9\u6cd5\u76f4\u63a5\u4ece\u4e00\u4e2a\u6307\u5b9a\u7684\u8303\u56f4\u4e2d\u968f\u673a\u62bd\u53d6\u5143\u7d20\uff0c\u5e76\u4fdd\u8bc1\u5143\u7d20\u4e0d\u91cd\u590d\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u5bfc\u5165<code>random<\/code>\u6a21\u5757\u3002<\/li>\n<li>\u4f7f\u7528<code>random.sample()<\/code>\u65b9\u6cd5\u751f\u6210\u5305\u542b1\u5230100\u7684\u968f\u673a\u6570\u7ec4\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import random<\/p>\n<h2><strong>\u751f\u6210\u5305\u542b1\u5230100\u7684\u968f\u673a\u6570\u7ec4<\/strong><\/h2>\n<p>random_array = random.sample(range(1, 101), 100)<\/p>\n<p>print(random_array)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u4ee3\u7801\u9996\u5148\u5bfc\u5165\u4e86<code>random<\/code>\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528<code>random.sample()<\/code>\u65b9\u6cd5\u4ece\u8303\u56f41\u5230100\u4e2d\u968f\u673a\u62bd\u53d6100\u4e2a\u6570\u5b57\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5728<code>random_array<\/code>\u53d8\u91cf\u4e2d\u3002\u6700\u540e\uff0c\u6253\u5370\u51fa\u751f\u6210\u7684\u968f\u673a\u6570\u7ec4\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u4ece\u591a\u4e2a\u65b9\u9762\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Python\u4e2d\u5c061\u5230100\u968f\u673a\u653e\u5165\u6570\u7ec4\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u4f7f\u7528random.sample()\u751f\u6210\u968f\u673a\u6570\u7ec4<\/h2>\n<\/p>\n<p><h3>1. \u5bfc\u5165random\u6a21\u5757<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528<code>random.sample()<\/code>\u65b9\u6cd5\u4e4b\u524d\uff0c\u9700\u8981\u5148\u5bfc\u5165<code>random<\/code>\u6a21\u5757\u3002<code>random<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u4e9b\u751f\u6210\u968f\u673a\u6570\u7684\u51fd\u6570\u548c\u65b9\u6cd5\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u65b9\u4fbf\u5730\u751f\u6210\u968f\u673a\u6570\u6216\u968f\u673a\u6392\u5217\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u4f7f\u7528random.sample()\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p><code>random.sample()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u4ece\u6307\u5b9a\u7684\u8303\u56f4\u4e2d\u968f\u673a\u62bd\u53d6\u6307\u5b9a\u6570\u91cf\u7684\u5143\u7d20\u3002\u8fd9\u4e2a\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6307\u5b9a\u6570\u91cf\u5143\u7d20\u7684\u5217\u8868\uff0c\u8fd9\u4e9b\u5143\u7d20\u662f\u4ece\u6307\u5b9a\u8303\u56f4\u4e2d\u968f\u673a\u62bd\u53d6\u7684\uff0c\u5e76\u4e14\u4e0d\u4f1a\u91cd\u590d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u5305\u542b1\u5230100\u7684\u968f\u673a\u6570\u7ec4<\/p>\n<p>random_array = random.sample(range(1, 101), 100)<\/p>\n<p>print(random_array)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4f7f\u7528<code>random.sample()<\/code>\u65b9\u6cd5\u4ece\u8303\u56f41\u5230100\u4e2d\u968f\u673a\u62bd\u53d6100\u4e2a\u6570\u5b57\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5728<code>random_array<\/code>\u53d8\u91cf\u4e2d\u3002\u7136\u540e\uff0c\u6253\u5370\u51fa\u751f\u6210\u7684\u968f\u673a\u6570\u7ec4\u3002<\/p>\n<\/p>\n<p><h3>3. \u8fd0\u884c\u7ed3\u679c<\/h3>\n<\/p>\n<p><p>\u8fd0\u884c\u4e0a\u8ff0\u4ee3\u7801\u540e\uff0c\u5c06\u5f97\u5230\u4e00\u4e2a\u5305\u542b1\u5230100\u7684\u968f\u673a\u6570\u7ec4\u3002\u6bcf\u6b21\u8fd0\u884c\u4ee3\u7801\u65f6\uff0c\u751f\u6210\u7684\u6570\u7ec4\u4f1a\u6709\u6240\u4e0d\u540c\uff0c\u56e0\u4e3a<code>random.sample()<\/code>\u65b9\u6cd5\u4f1a\u968f\u673a\u62bd\u53d6\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">[56, 23, 89, 12, 34, 78, 45, 67, 90, 11, 22, 54, 76, 33, 44, 88, 99, 7, 13, 5, 18, 70, 85, 42, 100, 9, 21, 2, 46, 19, 31, 38, 62, 14, 8, 6, 61, 49, 25, 35, 32, 4, 26, 71, 91, 84, 39, 64, 77, 65, 59, 40, 82, 66, 68, 55, 69, 36, 24, 41, 30, 87, 48, 17, 98, 92, 93, 81, 50, 53, 73, 52, 3, 29, 83, 15, 94, 43, 1, 28, 72, 60, 95, 37, 86, 47, 10, 97, 80, 75, 58, 20, 27, 63, 16, 74, 57, 96, 79, 51]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528random.shuffle()\u968f\u673a\u6392\u5217\u6570\u7ec4<\/h2>\n<\/p>\n<p><h3>1. \u5bfc\u5165random\u6a21\u5757<\/h3>\n<\/p>\n<p><p>\u540c\u6837\u5730\uff0c\u5728\u4f7f\u7528<code>random.shuffle()<\/code>\u65b9\u6cd5\u4e4b\u524d\uff0c\u9700\u8981\u5148\u5bfc\u5165<code>random<\/code>\u6a21\u5757\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u751f\u6210\u6709\u5e8f\u6570\u7ec4<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u751f\u6210\u4e00\u4e2a\u5305\u542b1\u5230100\u7684\u6709\u5e8f\u6570\u7ec4\u3002\u53ef\u4ee5\u4f7f\u7528<code>range()<\/code>\u51fd\u6570\u751f\u6210\u4e00\u4e2a\u5305\u542b\u6307\u5b9a\u8303\u56f4\u5185\u6570\u5b57\u7684\u5e8f\u5217\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u5305\u542b1\u5230100\u7684\u6709\u5e8f\u6570\u7ec4<\/p>\n<p>ordered_array = list(range(1, 101))<\/p>\n<p>print(ordered_array)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4f7f\u7528<code>range()<\/code>\u51fd\u6570\u751f\u6210\u4e00\u4e2a\u5305\u542b1\u5230100\u7684\u6709\u5e8f\u6570\u7ec4\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u5217\u8868\u3002\u7136\u540e\uff0c\u6253\u5370\u51fa\u751f\u6210\u7684\u6709\u5e8f\u6570\u7ec4\u3002<\/p>\n<\/p>\n<p><h3>3. \u4f7f\u7528random.shuffle()\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p><code>random.shuffle()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u968f\u673a\u6392\u5217\u4e00\u4e2a\u5217\u8868\u4e2d\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u968f\u673a\u6392\u5217\u6570\u7ec4<\/p>\n<p>random.shuffle(ordered_array)<\/p>\n<p>print(ordered_array)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4f7f\u7528<code>random.shuffle()<\/code>\u65b9\u6cd5\u968f\u673a\u6392\u5217<code>ordered_array<\/code>\u4e2d\u7684\u5143\u7d20\uff0c\u7136\u540e\uff0c\u6253\u5370\u51fa\u968f\u673a\u6392\u5217\u540e\u7684\u6570\u7ec4\u3002<\/p>\n<\/p>\n<p><h3>4. \u8fd0\u884c\u7ed3\u679c<\/h3>\n<\/p>\n<p><p>\u8fd0\u884c\u4e0a\u8ff0\u4ee3\u7801\u540e\uff0c\u5c06\u5f97\u5230\u4e00\u4e2a\u5305\u542b1\u5230100\u7684\u968f\u673a\u6570\u7ec4\u3002\u6bcf\u6b21\u8fd0\u884c\u4ee3\u7801\u65f6\uff0c\u751f\u6210\u7684\u6570\u7ec4\u4f1a\u6709\u6240\u4e0d\u540c\uff0c\u56e0\u4e3a<code>random.shuffle()<\/code>\u65b9\u6cd5\u4f1a\u968f\u673a\u6392\u5217\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">[45, 23, 89, 78, 34, 12, 56, 67, 90, 11, 22, 54, 76, 33, 44, 88, 99, 7, 13, 5, 18, 70, 85, 42, 100, 9, 21, 2, 46, 19, 31, 38, 62, 14, 8, 6, 61, 49, 25, 35, 32, 4, 26, 71, 91, 84, 39, 64, 77, 65, 59, 40, 82, 66, 68, 55, 69, 36, 24, 41, 30, 87, 48, 17, 98, 92, 93, 81, 50, 53, 73, 52, 3, 29, 83, 15, 94, 43, 1, 28, 72, 60, 95, 37, 86, 47, 10, 97, 80, 75, 58, 20, 27, 63, 16, 74, 57, 96, 79, 51]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e09\u3001\u6bd4\u8f83\u4e24\u79cd\u65b9\u6cd5\u7684\u4f18\u7f3a\u70b9<\/h2>\n<\/p>\n<p><h3>1. random.sample()\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p><strong>\u4f18\u70b9<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u7b80\u5355\u6613\u7528\uff0c\u53ea\u9700\u8981\u4e00\u884c\u4ee3\u7801\u5373\u53ef\u751f\u6210\u5305\u542b1\u5230100\u7684\u968f\u673a\u6570\u7ec4\u3002<\/li>\n<li>\u4fdd\u8bc1\u5143\u7d20\u4e0d\u91cd\u590d\u3002<\/li>\n<\/ul>\n<p><p><strong>\u7f3a\u70b9<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u9700\u8981\u989d\u5916\u7684\u5185\u5b58\u7a7a\u95f4\u6765\u5b58\u50a8\u751f\u6210\u7684\u968f\u673a\u6570\u7ec4\u3002<\/li>\n<\/ul>\n<p><h3>2. random.shuffle()\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p><strong>\u4f18\u70b9<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u53ef\u4ee5\u5728\u539f\u5730\u5bf9\u6570\u7ec4\u8fdb\u884c\u968f\u673a\u6392\u5217\uff0c\u4e0d\u9700\u8981\u989d\u5916\u7684\u5185\u5b58\u7a7a\u95f4\u3002<\/li>\n<\/ul>\n<p><p><strong>\u7f3a\u70b9<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u9700\u8981\u5148\u751f\u6210\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4\uff0c\u7136\u540e\u518d\u8fdb\u884c\u968f\u673a\u6392\u5217\uff0c\u6b65\u9aa4\u7a0d\u5fae\u590d\u6742\u4e00\u4e9b\u3002<\/li>\n<\/ul>\n<p><h2>\u56db\u3001\u5e94\u7528\u573a\u666f<\/h2>\n<\/p>\n<p><h3>1. \u6570\u636e\u5206\u6790<\/h3>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u4e2d\uff0c\u968f\u673a\u62bd\u6837\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u53ef\u4ee5\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\u4ece\u6570\u636e\u96c6\u4e2d\u968f\u673a\u62bd\u53d6\u6837\u672c\uff0c\u4ee5\u4fbf\u8fdb\u884c\u540e\u7eed\u7684\u5206\u6790\u548c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h3>2. \u6e38\u620f\u5f00\u53d1<\/h3>\n<\/p>\n<p><p>\u5728\u6e38\u620f\u5f00\u53d1\u4e2d\uff0c\u968f\u673a\u6027\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u56e0\u7d20\u3002\u53ef\u4ee5\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\u751f\u6210\u968f\u673a\u6570\u6216\u968f\u673a\u6392\u5217\u6570\u7ec4\uff0c\u4ee5\u4fbf\u5728\u6e38\u620f\u4e2d\u5b9e\u73b0\u968f\u673a\u4e8b\u4ef6\u6216\u968f\u673a\u5173\u5361\u3002<\/p>\n<\/p>\n<p><h3>3. <a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a><\/h3>\n<\/p>\n<p><p>\u5728\u673a\u5668\u5b66\u4e60\u4e2d\uff0c\u6570\u636e\u7684\u968f\u673a\u6392\u5217\u548c\u62bd\u6837\u662f\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u53ef\u4ee5\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\u5bf9\u6570\u636e\u8fdb\u884c\u968f\u673a\u5316\u5904\u7406\uff0c\u4ee5\u4fbf\u8fdb\u884c\u6a21\u578b\u8bad\u7ec3\u548c\u9a8c\u8bc1\u3002<\/p>\n<\/p>\n<p><h3>4. \u6d4b\u8bd5\u7528\u4f8b\u751f\u6210<\/h3>\n<\/p>\n<p><p>\u5728\u8f6f\u4ef6\u6d4b\u8bd5\u4e2d\uff0c\u751f\u6210\u968f\u673a\u7684\u6d4b\u8bd5\u7528\u4f8b\u662f\u5e38\u89c1\u7684\u9700\u6c42\u3002\u53ef\u4ee5\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\u751f\u6210\u968f\u673a\u6570\u6216\u968f\u673a\u6392\u5217\u6570\u7ec4\uff0c\u4ee5\u4fbf\u8fdb\u884c\u6d4b\u8bd5\u7528\u4f8b\u7684\u751f\u6210\u548c\u6267\u884c\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p><strong>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>random.sample()<\/code>\u65b9\u6cd5\u6216<code>random.shuffle()<\/code>\u65b9\u6cd5\u5c061\u5230100\u7684\u6570\u5b57\u968f\u673a\u653e\u5165\u6570\u7ec4\u3002<\/strong> <code>random.sample()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u4ece\u6307\u5b9a\u8303\u56f4\u4e2d\u968f\u673a\u62bd\u53d6\u5143\u7d20\uff0c\u5e76\u4fdd\u8bc1\u5143\u7d20\u4e0d\u91cd\u590d\u3002\u800c<code>random.shuffle()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u968f\u673a\u6392\u5217\u4e00\u4e2a\u5217\u8868\u4e2d\u7684\u5143\u7d20\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\uff0c\u53ef\u4ee5\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u8fdb\u884c\u64cd\u4f5c\u3002\u5728\u6570\u636e\u5206\u6790\u3001\u6e38\u620f\u5f00\u53d1\u3001\u673a\u5668\u5b66\u4e60\u548c\u8f6f\u4ef6\u6d4b\u8bd5\u7b49\u9886\u57df\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u751f\u62101\u5230100\u7684\u968f\u673a\u6570\u6570\u7ec4\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>random<\/code>\u6a21\u5757\u751f\u62101\u5230100\u7684\u968f\u673a\u6570\u6570\u7ec4\u3002\u9996\u5148\u5bfc\u5165<code>random<\/code>\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528<code>random.sample()<\/code>\u65b9\u6cd5\u9009\u62e9\u4e0d\u91cd\u590d\u7684\u968f\u673a\u6570\uff0c\u6216\u8005\u4f7f\u7528<code>random.randint()<\/code>\u751f\u6210\u6307\u5b9a\u8303\u56f4\u5185\u7684\u968f\u673a\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">import random\n\nrandom_array = random.sample(range(1, 101), 100)  # \u751f\u62101\u5230100\u7684\u968f\u673a\u6570\u6570\u7ec4\nprint(random_array)\n<\/code><\/pre>\n<p><strong>\u5982\u4f55\u786e\u4fdd\u751f\u6210\u7684\u968f\u673a\u6570\u7ec4\u4e2d\u7684\u6570\u5b57\u4e0d\u91cd\u590d\uff1f<\/strong><br \/>\u8981\u786e\u4fdd\u751f\u6210\u7684\u968f\u673a\u6570\u7ec4\u4e2d\u7684\u6570\u5b57\u4e0d\u91cd\u590d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>random.sample()<\/code>\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u4ece\u6307\u5b9a\u7684\u8303\u56f4\u5185\u968f\u673a\u9009\u62e9\u4e0d\u91cd\u590d\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff0c<code>random.sample(range(1, 101), 100)<\/code>\u53ef\u4ee5\u786e\u4fdd\u6570\u7ec4\u4e2d\u5305\u542b1\u5230100\u7684\u6240\u6709\u6570\u5b57\u4e14\u6ca1\u6709\u91cd\u590d\u3002\u8fd9\u6837\u53ef\u4ee5\u6709\u6548\u5730\u907f\u514d\u91cd\u590d\u95ee\u9898\u3002<\/p>\n<p><strong>\u80fd\u5426\u751f\u6210\u5305\u542b\u91cd\u590d\u6570\u5b57\u7684\u968f\u673a\u6570\u7ec4\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u53ef\u4ee5\u751f\u6210\u5305\u542b\u91cd\u590d\u6570\u5b57\u7684\u968f\u673a\u6570\u7ec4\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528<code>random.randint()<\/code>\u65b9\u6cd5\u5b9e\u73b0\uff0c\u8be5\u65b9\u6cd5\u5141\u8bb8\u5728\u7ed9\u5b9a\u8303\u56f4\u5185\u751f\u6210\u968f\u673a\u6570\uff0c\u53ef\u4ee5\u5728\u5faa\u73af\u4e2d\u8c03\u7528\u591a\u6b21\u6765\u586b\u5145\u6570\u7ec4\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">import random\n\nrandom_array_with_duplicates = [random.randint(1, 100) for _ in range(100)]  # \u751f\u6210\u5305\u542b\u91cd\u590d\u6570\u5b57\u7684\u968f\u673a\u6570\u6570\u7ec4\nprint(random_array_with_duplicates)\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u5141\u8bb8\u6570\u7ec4\u4e2d\u51fa\u73b0\u76f8\u540c\u7684\u6570\u5b57\uff0c\u589e\u52a0\u4e86\u968f\u673a\u6027\u7684\u591a\u6837\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u5c061\u5230100\u7684\u6570\u5b57\u968f\u673a\u653e\u5165\u6570\u7ec4\u3002 \u9996\u5148\uff0c\u53ef\u4ee5\u4f7f\u7528random.sample( [&hellip;]","protected":false},"author":3,"featured_media":1134653,"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\/1134648"}],"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=1134648"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1134648\/revisions"}],"predecessor-version":[{"id":1134654,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1134648\/revisions\/1134654"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1134653"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1134648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1134648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1134648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}