Today’s Snippet Saturday (actually, Sunday) is a quick shortcut for choosing one of several strings, objects, etc. randomly.
Now, I wouldn’t really recommend using this code in a project. There are ways to do the same thing that are much more readable and less error prone. Instead, I thought it was an interesting experiment to show off some of how AS3′s syntax works for those of you who may not have seen something like this.
What’s happening here? Let’s break it down.
The result, an array is created with three strings, a random number between 0.0 and (almost) 3.0 is generated, it is rounded down to an int between 0 and 2, that number is used as the index of the array to look up. The result will be randomly one of the three strings.
I hope you found this interesting!