ANNOUNCING THE 20 SMALL BASIC BOOK GIVEAWAY WINNERS: "Learn to Program with Small Basic: An Introduction to Programming with Games, Art, Science, and Math"

ABOUT THE GIVEAWAY

In today's blog post, we'll dig into a Small Basic sample that will select 10 random winners from folks who took the Small Basic 1.2 Feedback Survey!

Awhile ago we had a promotion to win the Small Basic book I cowrote with Majed Marji:

 

You can learn more about the book here:

 

            

 

No Starch Press is giving away 20 books as prizes to that contest!

  • 10 PRIZES: 1 Ebook for 10 randomly chosen survey participants
  • 10 PRIZES: 1 Printed Book for the Top 10 best feedback answers in the survey

 

And today we're announcing the winners!

 

10 FEEDBACK WINNERS

Here are the 10 winners who gave us great feedback and helped us find missing bugs (chosen by our Small Basic team, who acted as judges):

  1. David EW
  2. David P
  3. Sivaraj A
  4. Matthew P
  5. Petr V
  6. Joseph B
  7. Garth F
  8. Pete M
  9. Tiago B
  10. David W

Those 10 winners received emails to get their printed books!

Special thanks to all the participants who gave us great feedback! You helped us prioritize our bugs, feature back log, and we added a few bugs and feature ideas to our backlog, based on your feedback! (The good news is that we're using it as we're working on Small Basic 1.3, and so this feedback is very valuable.)

Now that we know our 10 Feedback winners, let's pick the 10 random winners!

 

SAMPLE TO PICK 10 RANDOM WINNERS

I'm going to do it as a Small Basic sample!

I wrote a Small Basic program to select the winners! I wrote this program in 14 lines of code (click it for a larger version, but be sure to come back):

SB_EbookWinners_14Lines02

First, I wrote a line that declares a simple array, which is like having one variable that collects an unlimited number of strings. It collects as many different strings or items of data content that I feed into it.

Here is the line:

contestants = "1=TB;2=KA;3=JN;4=TKG;5=TE;6=JDC;7=DBe;8=RAD;9=CA;10=CB;11=MT;12=JD;13=LM; 14=PH;15=JAu;16=DH;17=TMC;18=JAb;19=GC;20=DMK;21=DL;22=JC;23=DF;24=AHa; 25=GH;26=BR;27=RP;28=WC;29=SP;30=ArR;31=JH;32=AM;33=AmR;34=JI;35=RI;36=DBu; 37=BS;38=JK;39=EN;40=CK;41=AnH;42=OH;43=SG;44=DS;45=KP;46=SM"

That's all one line! It's just a long line.

In this case, I assigned 46 strings into an array. Those 46 strings are each just a few letters that represent the 46 contestants. I took the total number of people who took the survey, and then I subtracted any folks who already won the printed books (see 10 Feedback Winners above).

What was left was those 46 contestants. I assigned them to the contestants array.

Now I'm ready to start displaying out the text (yes, already!). I'm beginning with a bit of title text that will tell you what this list is about:

TextWindow.WriteLine("The Winners are:")

I used the TextWindow object, since I'm going to be displaying text in the text window. I used the TextWindow object's WriteLine method to write a line of text in the text window. And the text is "The Winners are:" to let the reader know very easily what this list is all about.

I'm ready for my next line! For my third line, I just added a blank line to make it easier to read.

It's time to start the For loop!

The fourth line gets the loop started:

For N = 1 To 10

This loop starts at the number 1 and goes 10 times. That's all this line means. So whatever is inside this loop gets 10 passes. We need to make each pass count!

The fifth line is the first line in our loop. This line picks one of the 10 winners:

winner = Math.GetRandomNumber(46)

We selected a winner! We use the Math object's GetRandomNumber method to, yup you guessed it, select a random number. The 46 means the random number will be between 1 and 46. Pretty easy! Then it's assigned into our new variable, winner. The variable is a container that holds one thing at a time. Now it's holding the number that corresponds to one of our 46 winners!

Our next three lines are interesting. These lines are just checking to see if the person has been picked yet. We can't pick someone more than once! That wouldn't be fair to the other 45 contestants! Check it out; here are lines 6-8 (all are still inside the For loop, so we run this check 10 times, once for each winner selection):

While (contestants[winner] = 0)

winner = Math.GetRandomNumber(46)

EndWhile

What just happened? Well, a While loop runs the loop only as long as the condition is true. The condition is contestants[winner] = 0. This uses the winner number we just randomly assigned (for example, let's say it picked the number 22 from the choices of 1 to 46). Then it checks into the array we declared (back in line 1), looks at the value of the winner number (in the example, it looks into the #22 spot), and sees if the value for that number is 0. Obviously, none of those strings are the number 0 (and the value of our contestants[22] spot in the array is JC)! So in our first iteration of our For loop, this While loop checks, finds the condition is false (nothing is valued at 0), and it never runs. It just skips ahead.

Then why am I using it? Well, later on I'm assigning values to zero after I select them as the winners! Why? Because this way I make sure we don't select the same winner twice! I'll explain this more in a bit.

Now line 9 is a blank space. Why? Sometimes your code just needs a break! It just needs some breathing room so that you can visually see where one thought ends before starting another thought.

Line 10 gets to write out the first line in our list of winners! Finally! Here it is:

TextWindow.WriteLine(N + ". " + contestants[winner])

We use WriteLine to display another line of text out in the text window. The N variable displays the first number in the list (since this is the first time we're running the loop, and we'll run it 10 times). So it displays 1. The plus symbol conctatenates (glues) the period with a space, so it looks like this: (1. ). Then the plus sign concatenates the value of our first winner (so if the randomly selected number for winner was 22, then it displays: 1. JC).

More about the N variable: The variable N is used by the For loop to count the loop from 1 to 10. Each time the loop runs, the For loop increments the value of N to one number higher. So by using the variable N here, we can display the number for each of the 10 lines. For example, we started at number 1 (the first time the For loop runs), and the first line in the list in the text window, displayed the number 1 (it was 1. JC). The next time the For loop runs, it adds 1 to the value of the variable N, so that it displays the number 2 on the second line of our list! Why didn't we just type out the numbers, like 1 and 2? Well, we're putting all this in a For loop so we don't have to type out 10 different lines of code for these different 10 numbers! We can just use the For loop to add one to the variable N instead. So the third time we run this For loop, the number gets incremented by 1 more, to the value of 3.

We have our first winner, displayed on the line! Our 11th line of code is just another space.

Next we're going to set our winner to the value of 0:

contestants[winner] = 0

Now that our winner is set to the value of 0 (instead of to JC), we won't select JC again!

Line 13 ends our For loop:

EndFor

And then line 14 gives us a blank line (so we get a nice space in the text window before you get the text, "Press any key to continue..."):

TextWindow.WriteLine("")

And that's our code! We did it in just 14 lines (with three spaces)! Let's look at all the lines here:

contestants = "1=TB;2=KA;3=JN;4=TKG;5=TE;6=JDC;7=DBe;8=RAD;9=CA;10=CB;11=MT;12=JD;13=LM;14=PH;15=JAu;

16=DH;17=TMC;18=JAb;19=GC;20=DMK;21=DL;22=JC;23=DF;24=AHa;25=GH;26=BR;27=RP;28=WC;

29=SP;30=ArR;31=JH;32=AM;33=AmR;34=JI;35=RI;36=DBu;37=BS;38=JK;39=EN;40=CK;41=AnH;42=OH;

43=SG;44=DS;45=KP;46=SM"

TextWindow.WriteLine("The Winners are:")

For N = 1 To 10

winner = Math.GetRandomNumber(46)

While (contestants[winner] = 0)

winner = Math.GetRandomNumber(46)

EndWhile

TextWindow.WriteLine(N + ". " + contestants[winner])

contestants[winner] = 0

EndFor

TextWindow.WriteLine("")

The second pass on the For loop

Now let's take a look at what happens the second time we run our For loop (remember we run it 10 times total):

  1. On line 5, the variable winner gets assigned a new random number, between 1 and 46.
  2. On lines 6-8, the While loop checks if the array value is set to 0. If it is, that means the person already won. So line 7 selects a new random winner, from 1-46, and then the While loop checks again to see if that person has won yet. The loop continues until it selects someone who hasn't won yet. Then it exits the loop and moves on...
  3. Line 10 displays the line for our second winner. In this case, it displays: 2. PH
  4. Line 12 sets the second winner to the value of 0, so we don't pick that person again!

Then we exit the For loop and go to the third pass! Make sense? If not, leave a comment below!

Get the code!

Want the code so you can play with it?

You can import the program with this code (in Small Basic, click the Import button):

  • RVG855

You can find an example run of the program, and get the code, on the online gallery:

And that leads us to the 10 winners selected by the program!

Selecting the Winners:

Here are the results of the program and what I saw in the text window when I ran it:

The Winners are:

1. JC

2. PH

3. CK

4. JN

5. RAD

6. KA

7. MT

8. GC

9. DF

10. DH

 

Press any key to continue...

Here is the screenshot:

SB_EbookWinners

We did it! We selected the 10 random winners using computer programming and by using a method that we know is truly random! =^)

There's probably a website out there that randomly selects winners for you, but since this is for Small Basic, and the whole point is to learn computer science, I turned it into a Small Basic sample!

 

10 RANDOM EBOOK WINNERS

Here are our 10 winners:

  1. John C
  2. Patteri H
  3. Carl K
  4. John N
  5. Ruth AD
  6. Karthikeyan A
  7. Matthew T
  8. Gary C
  9. David F
  10. David H

THANK YOU!

A big thanks go out to all 20 winners and everyone who took the survey! We've already put the information to use, and it will be very useful for the future of Small Basic!

And don't forget to check out the book and see if it's something that will help you:

Learn to Program with Small Basic: An Introduction to Programming with Games, Art, Science, and Math

Small Basic is the only computer programming syntax/text-based language and IDE/UI that was built specifically for kids and learners!

 

Keep things Small and Basic!

- Ninja Ed