RelicNews Forums

Go Back   RelicNews Forums > RDN - Relic Game Mods > Homeworld 2 - Tanis Shipyards > Archive Dump
User Name
Password
Register FAQ Members List Arcade Mark Forums Read



Reply
 
Thread Tools
Old 29th Jan 06, 6:26 AM Forum Rules   # 1
Mikail
Lost in the Web...
 
Mikail's Avatar
 
Join Date: Jun 2003
Location: %HW2_ROOT%

Random Number Functions

Here's some extra random number functions I created in Lua:
Code:
-- Randomly returns either 1 or -1. function randomSign() local ranNum = random() if (ranNum > 0.5) then return 1 else return -1 end end -- Randomly returns either 1 or 0. function randomBit() local ranNum = random() if (ranNum > 0.5) then return 1 else return 0 end end -- Works just like random(), but can accept zero as an argument. function random2(fVal1, fVal2) if (fVal2) then if ((fVal2 - fVal1) == 0) then return fVal2 else return random(fVal1, fVal2) end elseif (fVal1) then if (fVal1 == 0) then return 0 else return random(fVal1) end else return random() end end -- Works just like random(), but can accept zero as an argument and always returns a float value, not an integer. function random3(fVal1, fVal2) if (fVal2) then local tmpVal = random() * (fVal2 - fVal1) return fVal1 + tmpVal elseif (fVal1) then return random() * fVal1 else return random() end end


See the Lua 4.0 reference manual for a description of how the random() function works.
__________________
Download my HW2 mods, maps & tools. link

Last edited by Mikail : 19th Mar 08 at 3:58 PM.
Mikail is offline  
Reply



Go Back   RelicNews Forums > RDN - Relic Game Mods > Homeworld 2 - Tanis Shipyards > Archive Dump
User Name
Password
Register FAQ Members List Arcade Mark Forums Read



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




All times are GMT -7. The time now is 4:57 AM.

Page generated in 0.14167809 seconds (86.36% PHP - 13.64% MySQL) with 9 queries

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.