{ "type": "code_options", "author": "csdn.net", "source": "solution.md", "exercise_id": "17f01393a3a241609477ad9b49eae5d7", "keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法", "title": "循环随机取数组直到得出指定数字?", "desc": [ { "content": "\n举个例子:\n随机数字范围:0~100\n每组数字量:6(s1,s2,s3,s4,s5,s6)\n第二轮开始随机数字范围:新s1和新s2取值为旧s1和s2之间,新s3和新s4取值为旧s3和s4之间,新s5和新s6取值为旧s5和s6之间。\n跳出循环条件:任意数字=37\n如因s1=s2!=37&&s3=s4!=37&&s5=s6!=37使数组进入无意义无限循环,则重新取0~100六个数字并开始如上述第二轮随机的随机取值。", "language": "markdown" } ], "answer": [ { "content": "", "language": "python" } ], "prepared": [ [ { "content": "", "language": "python" } ], [ { "content": "", "language": "python" } ], [ { "content": "", "language": "python" } ] ], "template": { "content": "import random\ndef random_test():\n\trst_list = [random.randint(0,100) for i in range(0, 6)]\n\tprint(rst_list)\n\twhile 1:\n\t\ttemp = []\n\t\tfor k,v in enumerate(rst_list):\n\t\t\tif k%2==0:\n\t\t\t\ttemp.append(random.randint(min([rst_list[k],rst_list[k+1]]),max([rst_list[k],rst_list[k+1]])))\n\t\t\telse:\n\t\t\t\ttemp.append(random.randint(min(rst_list[k-1], rst_list[k]),max(rst_list[k-1], rst_list[k])))\n\t\trst_list = temp\n\t\tprint(rst_list)\n\t\tif 37 in rst_list:\n\t\t\tprint('rst_list:',rst_list)\n\t\t\treturn rst_list\n\t\telse:\n\t\t\tif rst_list[0]==rst_list[1] and rst_list[2]==rst_list[3] and rst_list[4]==rst_list[5]:\n\t\t\t\trst_list = [random.randint(0, 100) for i in range(0, 6)]\ndef main():\n\trandom_test()\nif __name__ == '__main__':\n\tmain()", "language": "python" }, "node_id": "dailycode-a9142d5aeaa848daac6817cae5a08bb1", "license": "csdn.net", "created_at": 1637894161, "topic_link": "https://bbs.csdn.net/topics/600469992" }