JS random 사용하기


JS random 사용하기

Math.random() 0.0~0.99999...사이에 랜덤한 숫자 생성 Math.random()*10 하면 0~9.99999...중에 랜덤한 숫자 생성 Math.floor() 소수 내림 Math.ceil() 소수 올림 Math.round() 반올림 const peoples=[ //peoples배열 { //오브젝트 1 name:"Deumi", age:19, }, { //오브젝트 2 이하생략... name:"고길동", age:49, }, { name:"철수", age:25, }, { name:"제이손", age:100, }, ] //peoples 배열 선언 //0~peoples배열만큼 숫자중 랜덤한 peoples 오브젝트 선택 (소수자리 버림) const Who=peoples[Math.floor(Math.random()*peoples.length)];...



원문링크 : JS random 사용하기