![]() ![]() What we need to do is just call this getWinner function. ![]() It is literally random as to the placement of who is the first person on the shuffled array. So that could be the first person, right? The first person here absolutely could be the second person or the third person. We return back just the first item in the shuffled array. We use zero because in an array, zero is the first item in the array. Then from that array, the only thing we need to do is get the first name, which is this bracket notation. Now it’s shuffled.īasically, each person's name here that we're going to get 1 through 10 here is put into an array and then shuffled. Then we put in temp and we return the entire array. The temp part in this script is where we move that person out there and replace it with someone else. It’s creating a random array here, in the part where it says: j = Math.floor(Math.random() * (i + 1) ) But here we're doing it in Google Apps Script, this Math.random. It's a pretty simple little for loop that uses that Math.random, which is exactly the same as that Rand formula. This is the code that I found online, which is really cool. Now what it does is it then gets all the values and it creates what, what we call a shuffleArray. The active sheet gets the last row that there is data. We just grab the active sheet, we make sure we get the sheet name, which is the Sheet1 tab. ![]() You can literally get this code in this sheet. I want to walk through this and share with you how you can use this yourself. I wanted to show you how to do that in Google Script or Apps Script. I'm not going to go into it in this one because I found a really cool piece of code in Apps Script that can shuffle an array. One way you could do this is by doing a formula with the Rand function. We want to get a random person from this list. You can copy and paste if it's something like people who are commenting or retweeting. Now, however you determine to get names or usernames may be Twitter handles into a Google sheet. It’s the holiday Christmas season and I just thought it would be really cool to create a giveaway in a Google Sheet. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |