---
title: "JAVA随机数Random"
author: "caryt"
date: "2013-06-27T11:15:00Z"
tags: []
slug: "java-random"
draft: false
lastmod: "2014-04-25T10:57:16Z"
id: 2054453
url: "https://caryt.iteye.com/blog/2054453"
---

/\**  
\*  
\* @author caryt  
\*  
\*/  
public class test {

/\**  
\* @param args  
\*/  
static int x\[]=new int\[15];  
public static void main(String\[] args) {  
// TODO Auto-generated method stub  
Random random=new Random();  
int x = 0,y = -1;  
do {  
x=random.nextInt(10);//0~10;  
y=random.nextInt(10);  
System.out.println("x: "+x+" y: "+y);

}while (x!=y);

}

}

out:x: 2 y: 3  
x: 0 y: 6  
x: 8 y: 7  
x: 4 y: 5  
x: 8 y: 8