Jump to content

generating random number in script


steve2112

Recommended Posts

i want to generate a random number at startup so in a script i use

 

local v = math.random(1, 7)

 

but it always gives me the same number, so i put

 

math.randomseed(os.time())

 

before it but it crashes on randomseed

 

any idea how to get a random seed value?

 

thx

 

UPDATE

 

scratch that, it seems it does seed random every time without randomseed, i guess the first few times i tried it just happened to come up with the same number


Edited by steve2112

My kit: i7-4790K@4GHz / 8GB - GTX 980ti + rift CV1 - X52 pro - Multi Keyboard Remapper - 2DOF motion sim (in development)

Link to comment
Share on other sites

If its just 1 number you after on startup, I would call math.random 2 or 3 times. The first generated number of a certain seed will always be the same. No idea why randomseed crashes for you. I've used it a few times with os.time() when testing things in DCS and its worked fine.

-16AGR- 16th Air Guards Regiment is always looking for pilots - http://www.16agr.com

 

EWRS - Early Warning Radar Script

 

Specs:

 

 

Gigabyte Sniper Z5-S

Intel i5-4670k 3.4GHz OC'd 3.9GHz w/ Thermaltake 120mm Water 3.0 Pro Liquid CPU Cooler

16GB RAM

Gigabyte GTX 1080

TM Hotas Warthog: SN: 06976

Saitek Pro Flight Combat Rudder Pedals

TrackIR5 with TrackClipPro & Oculus Rift

2x 28" 4k UHD Monitors (3840x2160 each) + 1280x1024

 

 

Link to comment
Share on other sites

If its just 1 number you after on startup, I would call math.random 2 or 3 times. The first generated number of a certain seed will always be the same. No idea why randomseed crashes for you. I've used it a few times with os.time() when testing things in DCS and its worked fine.

 

os.time should only work if the os library isn't sanitized, which it is by default... But yeah, its a good idea to do a few math.random() calls initially to make it more random when you actually need it.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...