How to count how many times a number generates

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
friendlyIntrovert
Prole
Posts: 1
Joined: Sat Feb 16, 2019 1:51 am

How to count how many times a number generates

Post by friendlyIntrovert »

So I am fairly new to LOVE and for a program I'm doing I'm have to create a for loop that runs a million times and generates random values between 0 -32. My only issue is trying to get program to count how many times each number was generated. If anyone could help, it would be much appreciated. :)
User avatar
pgimeno
Party member
Posts: 3549
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to count how many times a number generates

Post by pgimeno »

Hi, and welcome to the forums :) You just need to create a table with an entry for each possible number from 0 to 32, initially all zeros. That's easily done with a loop from 0 to 32. These are the counters, one for each number. Then you run the other loop, the one that repeats a million times, where you draw a number from 0 to 32 and add 1 to the counter for that number.

What to do with that table after the loop is up to you :) You can for example print the values on the terminal with another loop from 0 to 32.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 96 guests