No previous code will be perfect for a situation, that's why you learn what different functions do and then apply them in your own code. Although I can guarantee people have had very similar issues, as this is a very basic request.
As said above, Math.random() will do the job, making use of...