Skip to content
Permalink
d9ee70fd59
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
42 lines (33 sloc) 1.05 KB
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();
}
}