01: /**
02: * Copyright (C) 2006, 2007 David Bulmore, Software Sensation Inc.
03: * All Rights Reserved.
04: *
05: * This file is part of jCommonTk.
06: *
07: * jCommonTk is free software; you can redistribute it and/or modify it under
08: * the terms of the GNU General Public License (Version 2) as published by
09: * the Free Software Foundation.
10: *
11: * jCommonTk is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with jCommonTk; if not, write to the Free Software Foundation,
18: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19: */package jcommontk.utils;
20:
21: public class PseudoRandomID {
22: static long count;
23:
24: public synchronized static String getPseudoRandomID() {
25: if (count > Long.MAX_VALUE - 10000)
26: count = 0;
27:
28: String id = new String("" + ++count + Math.random())
29: .replaceAll("0\\.", "");
30:
31: if (id.length() > 18)
32: id = id.substring(0, 18);
33:
34: return id;
35: }
36:
37: public static Long getLongPseudoRandomID() {
38: return new Long(getPseudoRandomID());
39: }
40: }
|