---
title: "编程珠玑(1)"
author: "zhoucl"
date: "2011-08-29T14:10:43Z"
tags: []
categories: ["编程语言"]
slug: "1"
draft: false
lastmod: "2011-08-29T14:10:43Z"
id: 1160376
url: "https://zhoucl.iteye.com/blog/1160376"
---

开始看了下编程珠玑，书的开篇就是一个排序的问题，今天就来实践一下，稍作修改，如题目大意：生成1千万个1亿以内的不重复的数据集合.

```
public final static int count = 100000000;
private static boolean[] collect = new boolean[count];
private static int[] source = new int[count/10];

public void createDate() {
	int temp  = 0;
	for(int i = 0; i < count/10;) {
                temp = new Random().nextInt(count);
		if(!collect[temp]) {
			source[i] = temp;
			collect[temp] = true;
			System.out.println(i + " = " + source[i] );
			i++;
		}
	}
}
```

 这通过boolean来标识的话，速度确实加快了不少，直接变为了近O(n)了，不知道还能不能进行改进~~~