Hold a Giveaway Raffle in a Google Sheet

Get a random winner from a list of names. Also great to randomize tasks to do.

Sheet Resources

Video Transcript

0:00 Hello, when I'm recording this. It's December 5th, so it's just coming up on the holiday Christmas season. And I just thought it would be really cool to create a giveaway in a Google sheet.
0:14 Now, however you determine to get names or user names, maybe Twitter handles into a Google sheet. That's up to you.
0:23 You can use a Google form. You can copy and paste if it's something like people who are commenting or retweeting.
0:29 But yeah, any way you get 'em in here, we have a list. We want to get a random person from this list.
0:34 We want to get a winner. Okay? So one way you could do this is by doing a formula with the Rand function.
0:41 And I have a couple of videos already on that, on how to do random numbers. We just sort of multiply I'm not gonna go into it in this one because I found a really cool piece of code app script on online called that can shuffle an array.
0:59 And so I wanted to show you how to do that in Google script or App Script. And here we have the whole code.
1:06 And so wanna walk through this and, and, and share with you how you can use this yourself. You can literally get this code in this sheet joing two below.
1:17 And what's cool is it's pretty simple until we get to the shuffle array. We just grab the active sheet, we make sure we get the sheet name, this sheet one.
1:28 If you have sort of a entrance or something, if you change the name here, go into this code and change it in sheet one.
1:36 So entrance where you see that online three just have to change that. So we're gonna change it back to sheet one, just so that it's the same.
1:46 Okay, we're getting the last row of that sheet. So whatever sheet this is, it's getting the last row and it doesn't get the last row of like 1000.
1:57 It actually gets the last row that there is data. So in this case it'll be row 10. Okay? Now what it does is it then gets all the values and it creates what, what we call a shuffle array.
2:12 How it does this is this code that I found online, which is really cool. It, it's pretty simple little for loop that uses that math dot random, which is a very sim it's exactly the same as that ran formula.
2:24 But here we're doing it in Google App script, this math random, it's creating a random array here. Then it's getting a temporary moving that, that nu that person outta there.
2:37 Then we're putting, we're replacing someone else and then we put temp and we return the entire array and it's shuffled.
2:43 Basically each person's name here that we're gonna get one through 10 here is put into an array and then shuffled.
2:51 And then we get back the array here, we get back the array. Then from that array, the only thing we need to do is get the first name, which is this bracket notation, which is we use zero because in an array, zero is the first item in the array and that's it.
3:08 We return back just the first item in the shuffled array. So that could be the first person, right? The first person here absolutely could be, could be the second person or the third person.
3:18 It is literally random as to the placement of who is the first person on the shuffle array. And what we need to do is just call this get winner function.
3:29 So if you grab this script from the sheet or you copy the sheet and then you enter all of the names here, the only thing you need to do is due equals get winner.
3:41 You will get this this red line that says unknown function, get winner, but just hit enter. Make sure you have a capital W here, get winner.
3:51 And here we go. We got Camden Hall. If you want to pick more than one, what I would recommend is grabbing that person, moving them out, and then writing get winner again.
4:08 And now it actually got that same place. So we can do is we can do this again equals get winner.
4:17 Let's see, gonna get this Oakley Parker. So we just move them out, move Lily up and do get one again.
4:29 Maybe one three. Lily Cooper. Ah, this is interesting. So I was looking at this, I was like, oh, this range, if that's the random one.
4:39 So I looked at this range and actually we need to have a header here. We wanna have usually have like names or entrance, right?
4:49 There we go. So what we're looking at is the, is a range or a list of names starting on the second row in the first column.
5:03 That's as large as there are rows minus one and then one column. So that's good that we double check, we go get winner Genesis King, the last one.
5:21 Then we do get winner again. We can do this maybe very many times. We can even sort this way, right?
5:32 If you take out, it's gonna be a random one every time. So it's not gonna Mike Dogen. Okay? Again, maybe you have some kind of entry or giveaway or a raffle that you can give away multiple prices so you don't take anyone out, that's fine.
5:48 <inaudible>. And so we have four winners here, right in that order. And so this raffle code, this get winner, allows you to shuffle those names and get a winner.
5:57 And I think that's a pretty cool thing. We can use this in giveaways. We can do this in even task management.
6:03 Sometimes we want do a task or we have a, a large array of tasks or to-do list that's quite long and we're like, oh, where do we start?
6:10 We can use this to get a random task out of it. I think that would be a fun implementation. Also, you can put a list of names of people who need to do tasks or a priority queue.
6:21 If you have sort of things coming in and you don't want to do them in the order that they're coming in, you can sort of pick a random person to take each one.
6:30 So that might randomize things a little bit more instead of giving them tasks to the first person, the second task to the second person, third task and third person, get a random one.
6:39 And, you know, some people might get doubled up, but over time, you know, customer service account or customer service representatives, it, it's random.
6:46 We're always, everybody's gonna get equal over a great deal of time. So I think this is pretty cool. Go grab the the link below to get a copy of this, but.

Better Sheets