https://7942yongdae.tistory.com/96
1.자바스크립트
function shuffle(array) {
for (let index = array.length - 1; index > 0; index--) {
// 무작위 index 값을 만든다. (0 이상의 배열 길이 값)
const randomPosition = Math.floor(Math.random() * (index + 1));
// 임시로 원본 값을 저장하고, randomPosition을 사용해 배열 요소를 섞는다.
const temporary = array[index];
array[index] = array[randomPosition];
array[randomPosition] = temporary;
}
}
const numbers = [1, 2, 3,4,5,6];
shuffle(numbers)
console.log(numbers)
package random;
import java.util.Random;
public class test {
public static void main(String[] args) {
int tmp=0;
int size =10;
int i =0;
int[] test = new int[10];
Random rnd = new Random();
for(i=0;i<10;i++) {
test[i] =i;
}
for(i=0;i<10;i++) {
int des =rnd.nextInt(size);
tmp = test[i];
test[i] = test[des];
test[des] = tmp;
}
for(int t=0;t<10;t++) {
System.out.println(""+test[t]);
}
}
}
jsp
<%!
public static String getrndnum(int num){
String str = "";
Random ran = new Random();
int number = ran.nextInt(num)+1;
str = Integer.toString(number);
return str;
}%>
https://blog.naver.com/PostView.naver?blogId=ouo7581&logNo=221481568633