Skip to content

Instantly share code, notes, and snippets.

@egoing
Last active July 5, 2017 13:36
Show Gist options
  • Save egoing/07286822f28b57e7ad76fdfe3862121e to your computer and use it in GitHub Desktop.
Save egoing/07286822f28b57e7ad76fdfe3862121e to your computer and use it in GitHub Desktop.
추첨
function shuffle(a) {
var j, x, i;
for (i = a.length; i; i--) {
j = Math.floor(Math.random() * i);
x = a[i - 1];
a[i - 1] = a[j];
a[j] = x;
}
}
function draw(){
// 당첨 여부를 표시하는 셀
const MARKCELL = 'M';
// 당첨자의 수
const SELECT_NUM = 80;
// 시작 데이터의 행 수
const DATA_START_ROW_NUM = 2;
// 마지막 데이터의 행 수
const DATA_END_ROW_NUM = 356;
var sheet = SpreadsheetApp.getActiveSheet();
var dataRange = sheet.getRange('A'+DATA_START_ROW_NUM+':K'+DATA_END_ROW_NUM);
var data = dataRange.getValues();
var dataArray = [];
for (var i in data) {
var row = data[i];
row.unshift(i);
dataArray.push(row);
}
shuffle(dataArray);
dataArray.splice(SELECT_NUM);
for(person in dataArray){
var id = dataArray[person][0];
SpreadsheetApp.getActiveSheet().getRange(MARKCELL+(DATA_START_ROW_NUM+Number(id))).setValue('당첨');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment