Permalink
Cannot retrieve contributors at this time
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?
react-native-bluetooth-scan/lib/android/src/main/java/com/scan/BluezonerIdGenerator.java /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
42 lines (33 sloc)
1.05 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | |
| } | |
| } |