From the course: Learning the Go Standard Library

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using random numbers

Using random numbers - Go Tutorial

From the course: Learning the Go Standard Library

Start my 1-month free trial

Using random numbers

- [Instructor] Now that we've seen how to generate random values, let's take what we've learned and apply it to some useful scenarios. So let's go ahead in chapter 3 in the start folder we're going to go and open up the UseRand folder, and we'll open up usingrand_start. So first we're going to see how to use the shuffle function to see how to randomize an array of values. So here I have a string with six words in it. So how would we randomize their order? Well, we saw one way to do this in a previous video by using the permutations function but we can also do it with the dedicated shuffle function. So first let's use the fields function from the strings package, which we saw earlier to split numstring into an array of words. And that means, of course I'm going to import my strings package, and I'll need the format package, so it's important that as well. All right, so now we need to use the shuffle function and the shuffle…

Contents