Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Helpers/RandomHelper.java
1 | package org.kde.kdeconnect.Helpers; | 1 | package org.kde.kdeconnect.Helpers; | ||
---|---|---|---|---|---|
2 | 2 | | |||
3 | 3 | | |||
4 | import java.security.SecureRandom; | 4 | import java.security.SecureRandom; | ||
5 | 5 | | |||
6 | public class RandomHelper { | 6 | public class RandomHelper { | ||
7 | public static SecureRandom secureRandom = new SecureRandom(); | 7 | public static SecureRandom secureRandom = new SecureRandom(); | ||
8 | 8 | | |||
9 | private static final char[] symbols = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"+ | 9 | private static final char[] symbols = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + | ||
10 | "abcdefghijklmnopqrstuvwxyz"+ | 10 | "abcdefghijklmnopqrstuvwxyz" + | ||
11 | "1234567890").toCharArray(); | 11 | "1234567890").toCharArray(); | ||
12 | 12 | | |||
13 | 13 | | |||
14 | public static String randomString(int length) { | 14 | public static String randomString(int length) { | ||
15 | char[] buffer= new char[length]; | 15 | char[] buffer = new char[length]; | ||
16 | for (int idx = 0; idx < length; ++idx) { | 16 | for (int idx = 0; idx < length; ++idx) { | ||
17 | buffer[idx] = symbols[secureRandom.nextInt(symbols.length)]; | 17 | buffer[idx] = symbols[secureRandom.nextInt(symbols.length)]; | ||
18 | } | 18 | } | ||
19 | return new String(buffer); | 19 | return new String(buffer); | ||
20 | } | 20 | } | ||
21 | 21 | | |||
22 | } | 22 | } |