Skip to content

Instantly share code, notes, and snippets.

@marocchino
Created May 9, 2012 07:41
Show Gist options
  • Save marocchino/2642728 to your computer and use it in GitHub Desktop.
Save marocchino/2642728 to your computer and use it in GitHub Desktop.
오브젝트의 가중치에따라 렌덤하게 선택함
banners = [
priority:10
,
priority:10
,
priority:20
,
priority:30
,
priority:40
]
banner = do (banners)->
total = []
for banner,i in banners
for _ in [1..banner.priority]
total.push i
banners[total[Math.floor(Math.random() * total.length)]]
console.log banner
@marocchino
Copy link
Author

cyluss횽의 코드에서 몇개 훔쳐왔음!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment