The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb






Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to compare random values
Author Message
XuN
Sphere Developer
*****

Posts: 852
Likes Given: 102
Likes Received: 156 in 119 posts
Joined: Jul 2013
Reputation: 30



Post: #16
RE: How to compare random values
<R20> returns a random number between 1 and 20 (a total of 20 possibilities), <r0,20> returns a random number between 0 and 20 (21 numbers in total).

BTW, now that you realised to do it, and learned in the proccess i'll show you a function I had for this:

Code:
[function GetRandomsFromTotal]        //GetRandomsFromTotal 5,100 returns 5 random* numbers wich sum 100. The random is calculated this way: BaseNum=(100/5), Result=RAND(BaseNum - argv[0],Basenum + argv[0])
local.amount=<argv[0]>
local.total=<argv[1]>
local.max=<qval (<isempty <argv[2]>>==0)?<argv[2]>:<eval (<argv[1]>/<argv[0]>)+<argv[0]>>>
local.min=<qval (<isempty <argv[3]>>==0)?<argv[3]>:<eval (<argv[1]>/<argv[0]>)-<argv[0]>>>
if (<local.min><0)
    local.min=0
endif
local.res=0
for 1 <local.amount>    // Here the results are created, nothing is checked so all of then can be the max <local.max> or the min... shit happens?
    local.ret_<dlocal._for>=<r<local.min>,<local.max>>
    local.res +=<local.ret_<dlocal._for>>
endfor
local.pointer=1
while <local.res>><local.total>    // So this is a check preventing the total result being higher than <argv[1]> and any result to be lower than <local.min>
    if (<local.ret_<dlocal.pointer>>><local.min>)
        local.ret_<dlocal.pointer> -=1
        local.res --
    endif
    local.pointer ++    // local.pointer is just going throught all the results decreasing (in this case) or increasing (in the next while) all the values by 1 until the requirements are done.
    if (<local.pointer>><local.amount>)
        local.pointer=1
    endif
endwhile
while <local.res><<local.total>    // and this one prevents anyone being lower than <argv[1]>
    if (<local.ret_<dlocal.pointer>><<local.max>)
        local.ret_<dlocal.pointer> +=1
        local.res ++
    endif
    local.pointer ++
    if (<local.pointer>><local.amount>)
        local.pointer=1
    endif
endwhile
//so with these 2 whiles Sphere ensured that all the values does sum the total of <argv[1]> we create the return value.
local.ret=0    //first value will be a 0 so we don't check in every for loop if the local is empty to create it or not.
for 1 <local.amount>
    local.ret=<local.ret>,<dlocal.ret_<dlocal._for>>
endfor
return <streat <local.ret>> // so here we remove the first value (the 0) and return the rest.
This will return the values separated with commas, ie: local.res=<GetRandomsFromTotal 5,20> will return a total of 5 random values which, in total, do not pass from 20. It also applies some logic to the calcs... numbers have a minimum value and a maximum value: in this case min value would be (20/5)-5=-1 and it will be fixed to 0 if that happens, the max would be (20/5)+5=9. This is done to create values between some certain range that let Sphere do its calcs easier. It won't be nice if the first random is 20 and the rest have to be 0 IMO.
(This post was last modified: 06-18-2014 07:28 PM by XuN.)
06-18-2014 07:19 PM
Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes XuN's post
Post Reply 


Messages In This Thread
How to compare random values - kn4tseb - 06-17-2014, 01:28 PM
RE: How to compare random values - XuN - 06-17-2014, 05:58 PM
RE: How to compare random values - kn4tseb - 06-18-2014, 12:05 AM
RE: How to compare random values - Seron - 06-18-2014, 12:50 AM
Re: How to compare random values - Extreme - 06-18-2014, 02:14 AM
RE: How to compare random values - Coruja - 06-18-2014, 02:21 AM
RE: How to compare random values - kn4tseb - 06-18-2014, 02:42 AM
RE: How to compare random values - kn4tseb - 06-18-2014, 07:22 AM
RE: How to compare random values - Extreme - 06-18-2014, 07:45 AM
RE: How to compare random values - Skul - 06-18-2014, 07:31 AM
RE: How to compare random values - kn4tseb - 06-18-2014, 07:51 AM
RE: How to compare random values - Extreme - 06-18-2014, 07:59 AM
RE: How to compare random values - Skul - 06-18-2014, 08:00 AM
RE: How to compare random values - kn4tseb - 06-18-2014, 08:08 AM
RE: How to compare random values - kn4tseb - 06-18-2014, 09:12 AM
RE: How to compare random values - XuN - 06-18-2014 07:19 PM
RE: How to compare random values - Coruja - 06-19-2014, 12:49 AM
RE: How to compare random values - kn4tseb - 06-19-2014, 01:33 PM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)