Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Printing random numbers in a certain range of numbers? [closed]

Asked by 6 years ago

The concept sounds easy but I have no idea where to start. Example

printed a random number between 1 and 10

Closed as Not Constructive by minikitkat

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
awfulszn 394 Moderation Voter
6 years ago

Okay, firstly this is not a request site.

So, you will want it to actually be random, so we add this line.

math.randomseed(tick()) -- Generate random seed.
math.random() -- Throw out first not-so random number, which is a known limitation of lua.

Now, we want to get a number within a range of other numbers, for example, between 1 and 10. To do this we will use math.random() and we will store it in a variable called range.

range = math.random(1, 10)

Now we will print it to the console.

print(range)

Full Script;

math.randomseed(tick())
math.random()

range = math.random(1, 10)
print(range)

If you would like any more help, don't hesitate to ask. If I solved your problem, please hit the accept button of this answer.

Good Luck!

0
I dont understand how to not "request" something LOL. you are REQUESTING something no matter what if you are asking something. lol MusicalDisplay 173 — 6y
0
whether you are requesting an answer or an example you are requesting something no matter what lol MusicalDisplay 173 — 6y
0
No. The rule is that you must try to make it yourself, then if it fails, you post the code here, explain your problem and what you have done to fix it. Theoretically, I shouldn't have even posted my answer. I'll now report this post as to discourage it from happening any further. awfulszn 394 — 6y
0
No. The rule is that you must try to make it yourself, then if it fails, you post the code here, explain your problem and what you have done to fix it. Theoretically, I shouldn't have even posted my answer. I'll now report this post as to discourage it from happening any further. awfulszn 394 — 6y
Ad