-
Notifications
You must be signed in to change notification settings - Fork 41
/
BluezonerIdGenerator.java
42 lines (33 loc) · 1.05 KB
/
BluezonerIdGenerator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.scan;
import java.util.Random;
/**
* Class Create BluezonerId random
* @author khanhxu
*/
public class BluezonerIdGenerator {
/**
* Create BluezonerId
* @param numberChar
* @return
*/
public static String createBluezonerId(int numberChar) {
// Char random
final String charRandom = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
final int charRandomLength = charRandom.length();
// String
StringBuilder bluezonerIdBuilder = new StringBuilder();
// Random
Random rand = new Random(System.currentTimeMillis());
// for tao numberChar ki tu
for (int i = 0; i < numberChar; i++) {
// Check
long randomValue = Math.abs(rand.nextLong());
// Index
int index = (int) (randomValue % charRandomLength);
// Create
bluezonerIdBuilder.append(charRandom.substring(index, index + 1));
}
// Ret
return bluezonerIdBuilder.toString();
}
}