/* GenesisChess, an Android chess application
 * Copyright 2022, Justin Madru (justin.jdm64@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.chess.genesis.util;

import java.util.concurrent.*;
import android.os.*;
import androidx.compose.runtime.*;

public class Util
{
	private Util() {}

	public static void runThread(Runnable runner)
	{
		Executors.newSingleThreadExecutor().execute(runner);
	}

	public static void runUI(Runnable runner)
	{
		new Handler(Looper.getMainLooper()).post(runner);
	}

	public static <T> MutableState<T> getState(T val)
	{
		return SnapshotStateKt.mutableStateOf(val, SnapshotStateKt.structuralEqualityPolicy());
	}
}

@@ -683,16 +683,40 @@
 .util;%0A%0A
+import java.security.*;%0A
 import j
@@ -734,24 +734,24 @@
 ncurrent.*;%0A
-
 import andro
@@ -815,16 +815,129 @@
  Util%0A%7B%0A
+%09private final static String SUID_CHARS = %22abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-_.~%22;%0A%0A
 %09private
@@ -1213,16 +1213,16 @@
 val)%0A%09%7B%0A
-
 %09%09return
@@ -1305,11 +1305,531 @@
 y());%0A%09%7D
+%0A%0A%09public static String getSUID()%0A%09%7B%0A%09%09var rand = new SecureRandom();%0A%09%09var buff = new StringBuilder();%0A%0A%09%09buff.append(randChar(rand, true));%0A%09%09for (int i = 0; i %3C 6; i++) %7B%0A%09%09%09buff.append(randChar(rand, false));%0A%09%09%7D%0A%09%09buff.append(randChar(rand, true));%0A%09%09return buff.toString();%0A%09%7D%0A%0A%09private static char randChar(SecureRandom rand, boolean onlyAlphNum)%0A%09%7B%0A%09%09char c;%0A%09%09do %7B%0A%09%09%09c = SUID_CHARS.charAt(Math.abs(rand.nextInt() %25 SUID_CHARS.length()));%0A%09%09%7D while (onlyAlphNum && !Character.isLetterOrDigit(c));%0A%09%09return c;%0A%09%7D
 %0A%7D%0A

add util to generate short ID