]> git.basschouten.com Git - openhab-addons.git/blob
6365665f662df4018e39cf3319c7728b8a0d87d8
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.bluetooth.util;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * This is a n string utility class
19  *
20  * @author Leo Siepel - Initial contribution
21  *
22  */
23 @NonNullByDefault
24 public class StringUtil {
25
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));
31         }
32
33         return sb.toString();
34     }
35
36     public static String randomAlphabetic(int length) {
37         return StringUtil.randomString(length, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz");
38     }
39
40     public static String randomHex(int length) {
41         return StringUtil.randomString(length, "0123456789ABCDEF");
42     }
43
44     public static String randomAlphanummeric(int length) {
45         return StringUtil.randomString(length, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvxyz");
46     }
47 }