Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6532775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:02:43+00:00 2026-05-25T10:02:43+00:00

If I create a simple lua script file: test.lua #!/usr/bin/env lua local var =

  • 0

If I create a simple lua script file:

test.lua

#!/usr/bin/env lua

local var = math.random(100)
print(var)

It will always print the same value when called, even though it really should be a new random value at each call.

My guess is that the script gets compiled(?) to for example:

#!/usr/bin/env lua

local var = 82
print(var)

(if 82 was the random value at first call)

What can I do to make sure that a new (?)bytecode gets compiled(?) each time I call the script, so that I can get a fresh random value at each execution of the script?

The reason I added the (?) is that I don’t even know if scripts get compiled at all or what happens to them when they are called, but something like that is clearly happening since I get the same value all the time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:02:44+00:00Added an answer on May 25, 2026 at 10:02 am

    Your script is not being kept as bytecode, it’s just that the same default random seed is used at every run. This has the effect you’re seeing: you get the same “random” sequence every time you run your script.

    You should initialize it by doing, for example

    math.randomseed(os.time())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I create simple test PDF document using iTextSharp. I'm just using PdfContentByte to show
I am trying to create simple user registration form. I have an index.html file
is there a way to create a standalone executable from a simple lua scripts?
I want create simple puzzle to select random 5 names from input. Lets say
I try to create simple file upload service in C++. I get all user
I need to create simple reusable javascript object publishing several methods and parameterized constructor.
I know how to create simple object and add dynamically properties to it. object
I would like to create simple objects at runtime (textbox, label, etc) and add
How to create simple C# Binary socket server (Not WCF!) Who knows the Simplest
How to create simple PHP COMET server page displaying current time? I need code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.