{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "4d7e67df30b441d4ab27995957d4ce62",
  "keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法",
  "title": "随机抽样",
  "desc": [
    {
      "content": "\n从数组a[]={1,2,3,4,5,6,7,8,9,10}中随机抽取5个数且不重复",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "java"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ]
  ],
  "template": {
    "content": "import java.util.HashSet;\nimport java.util.Random;\nimport java.util.Set;\nclass java_803899 {\n\tpublic static void main(String[] args) {\n\t\tint a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };\n\t\tRandom r = new Random();\n\t\tint count = 10;\n\t\twhile (count-- > 0) {\n\t\t\tSet<Integer> result = new HashSet<Integer>(5);\n\t\t\twhile (result.size() < 5) {\n\t\t\t\tint index = r.nextInt(10) % 10;\n\t\t\t\tint currentData = a[index];\n\t\t\t\tif (result.contains(currentData)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tSystem.out.print(\"随机加入：\" + currentData);\n\t\t\t\tresult.add(currentData);\n\t\t\t}\n\t\t\tSystem.out.println(\"第\" + count + \"次，last随机数：\" + result);\n\t\t}\n\t}\n}",
    "language": "java"
  },
  "node_id": "dailycode-3d37655535b94c67973752f1082916b1",
  "license": "csdn.net",
  "created_at": 1637894161,
  "topic_link": "https://bbs.csdn.net/topics/600470284"
}