---
title: "java双色球"
author: "clgoogle"
date: "2013-02-26T22:45:33Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2013-05-18T13:17:02Z"
id: 1815591
url: "https://clgoogle.iteye.com/blog/1815591"
---

[![](http://time-earn.com/images/468.gif)](http://time-earn.com/?ref=clgoogle)

红球 33 个球 (01~33) 取 六 蓝球 16 个球 (01~16) 取 一 Random r = new Random(); String\[] balls ={"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33"}; boolean\[] used = new boolean\[balls.length]; String\[] ball = new String\[6]; int num = 1; for(int i=0;i&lt;ball.length;i++){ int index = r.nextInt(balls.length);//0~32 while(used\[index]){ index = r.nextInt(balls.length); } used\[index]=true; ball\[i]=balls\[index]; } Arrays.sort(ball); ball = Arrays.copyOf(ball,ball.length+1); int index = r.nextInt(16); ball\[ball.length-1]=balls\[index]; System.out.println(Arrays.toString(ball));