2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.bluetooth.util;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
18 * This is a n string utility class
20 * @author Leo Siepel - Initial contribution
24 public class StringUtil {
26 public static String randomString(int length, String charset) {
27 StringBuilder sb = new StringBuilder(length);
28 for (int i = 0; i < length; i++) {
29 int index = (int) (charset.length() * Math.random());
30 sb.append(charset.charAt(index));
36 public static String randomAlphabetic(int length) {
37 return StringUtil.randomString(length, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz");
40 public static String randomHex(int length) {
41 return StringUtil.randomString(length, "0123456789ABCDEF");
44 public static String randomAlphanummeric(int length) {
45 return StringUtil.randomString(length, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvxyz");