“Menghasilkan string acak” Kode Jawaban

menghasilkan string acak di java

import java.util.Random;

public class Generator {
	public static String generateRandomPassword(int len) {
		String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijk"
          +"lmnopqrstuvwxyz!@#$%&";
		Random rnd = new Random();
		StringBuilder sb = new StringBuilder(len);
		for (int i = 0; i < len; i++)
			sb.append(chars.charAt(rnd.nextInt(chars.length())));
		return sb.toString();
	}
}
Vishal

menghasilkan python string acak

import string
import random

length=5
#python2
randomstr = ''.join(random.sample(string.ascii_letters+string.digits,length))


#python3
randomstr = ''.join(random.choices(string.ascii_letters+string.digits,k=length))

                                  
Worrisome Wallaby

Menghasilkan string acak

private static Random random = new Random();
public static string RandomString(int length)
{
    const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    return new string(Enumerable.Repeat(chars, length)
      .Select(s => s[random.Next(s.Length)]).ToArray());
}
Excited Echidna

Python menghasilkan string acak

''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(N))
Strange Salmon

String acak

private static Random random = new Random();

public static string RandomString(int length)
{
    const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    return new string(Enumerable.Repeat(chars, length)
        .Select(s => s[random.Next(s.Length)]).ToArray());
}
PrashantUnity

Menghasilkan string acak

Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
Chinanu Prince

Jawaban yang mirip dengan “Menghasilkan string acak”

Pertanyaan yang mirip dengan “Menghasilkan string acak”

Lebih banyak jawaban terkait untuk “Menghasilkan string acak” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya