Skip to content

Instantly share code, notes, and snippets.

@yeyuguo
Created June 21, 2021 05:36
Show Gist options
  • Save yeyuguo/9572744108f05d500204e44155eb0ae7 to your computer and use it in GitHub Desktop.
Save yeyuguo/9572744108f05d500204e44155eb0ae7 to your computer and use it in GitHub Desktop.
创建随时数组
function createRandom(start, end) {
const range = end - start
return start + Math.round(range * Math.random())
}
function createList(max=100) {
const getInt = ()=> createRandom(1, max)
const result = []
let count = 0
while(count < max) {
const num = getInt()
let index = num === 0 ? 0 : num -1
if(result[index] === undefined) {
result[index] = num
count++
}
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment