SphereCommunity
Random function - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: Script Help (/Forum-Script-Help)
+--- Thread: Random function (/Thread-Random-function)

Pages: 1 2 3


RE: Random function - WRWR - 07-12-2012 06:56 PM

how to get random number from 1, 2, 6, 7, 13, 19, 22, 24 only, for example?


RE: Random function - darksun84 - 07-12-2012 07:53 PM

Hmm you can try this :

[DEFNAME rand_defs]
random_list 1,2,6,7,13,19,22,24

[FUNCTION calc_random ]//This function take as input <def.random_list>
local.result = <R<argv>> // argv holds the total number of random_list, 8 in our case,since argv is 0 based we will have a result from 0 to 8-1
return <argv[<dlocal.result>]>

In theory is correct, i cannot test it right now but i think it's fineShock

Maybe there are already some random functions that use intervals, or it's possible to use weighted random like
local.result = {{1}1{2}1{6}1{7}1{13}1{19}1{22}1{24}1} where 1 is the weight, so we have a chance of 1/8 to get 1 or 2 or 6 etc..
I think this one works too