Skip to content
lsl.devlsl.devLSL Dev

llListStatistics

function
Function syntax
float llListStatistics(
  1. integer operation,// LIST_STAT_* constant of the statistical operation to perform. Values: ListStatisticsOperation
  2. list src// List of numbers to analyze.
);
Returns
float
Energy
10

If a list entry type is not a float or an integer it is silently ignored. Returns the numeric result of the statistical aggregate function operation (a LIST_STAT_* constant) on the numeric list src.

Returns a float that is the result of performing statistical aggregate function operation on src.

How to use
float result = llListStatistics(0, []);
ConstantDescription
LIST_STAT_RANGE0Calculates the range.
LIST_STAT_MIN1Calculates the smallest number.
LIST_STAT_MAX2Calculates the largest number.
LIST_STAT_MEAN3Calculates the mean (average).
LIST_STAT_MEDIAN4Calculates the median number.
LIST_STAT_STD_DEV5Calculates the standard deviation.
LIST_STAT_SUM6Calculates the sum.
LIST_STAT_SUM_SQUARES7Calculates the sum of the squares.
LIST_STAT_NUM_COUNT8Determines the number of float and integer elements.
LIST_STAT_GEOMETRIC_MEAN9Calculates the geometric mean.
Example 1
5 collapsed lines
// Show results for each operation for a sample list
default
{
state_entry()
{
list LX = [-1, 3.33, 17, "object", -4.5, 0.8675 ];
llSay(0, "G.Mean= " + (string) llListStatistics(LIST_STAT_GEOMETRIC_MEAN, LX) ); // 0. 000000
llSay(0, "Max= " + (string) llListStatistics(LIST_STAT_MAX, LX) ); // 17.000000
llSay(0, "Min= " + (string) llListStatistics(LIST_STAT_MIN, LX) ); // -4.500000
llSay(0, "Mean= " + (string) llListStatistics(LIST_STAT_MEAN, LX) ); // 3.139500
llSay(0, "Median= " + (string) llListStatistics(LIST_STAT_MEDIAN, LX) ); // 0.867500
llSay(0, "Count= " + (string) llListStatistics(LIST_STAT_NUM_COUNT, LX) ); // 5.000000
llSay(0, "Range= " + (string) llListStatistics(LIST_STAT_RANGE, LX) ); // 21.500000
llSay(0, "Std.Dev= " + (string) llListStatistics(LIST_STAT_STD_DEV, LX) ); // 8.258468
llSay(0, "Sum= " + (string) llListStatistics(LIST_STAT_SUM, LX) ); // 15.697500
llSay(0, "Sum of squares= " + (string) llListStatistics(LIST_STAT_SUM_SQUARES, LX) ); // 322.091500
}
}
// Note that LSLEditor produces "NaN" (Not A Number) for the geometric mean above. Geometric mean applies only to numbers of the same sign.
Example 2
// shows just how bad SL is behaving and demonstrates the use of llListStatistics()
list dil_s;
list fps_s;
19 collapsed lines
integer ticks = 0;
default
{
state_entry()
{
llSetTimerEvent(1.0);
}
on_rez (integer parm)
{
llResetScript();
}
timer()
{
dil_s = llList2List(dil_s + llGetRegionTimeDilation(), -60, -1);
fps_s = llList2List(fps_s + llGetRegionFPS(), -60, -1);
if(3 <= ++ticks)
{
llSetText(
"Dilation: min="+(string) llListStatistics(LIST_STAT_MIN, dil_s) + ", mean=" +
(string) llListStatistics(LIST_STAT_MEAN, dil_s) + ", max=" +
(string) llListStatistics(LIST_STAT_MAX, dil_s) + ", std.dev=" +
(string) llListStatistics(LIST_STAT_STD_DEV, dil_s) + "\n" +
"FPS: min="+(string) llListStatistics(LIST_STAT_MIN, fps_s) + ", mean=" +
(string) llListStatistics(LIST_STAT_MEAN, fps_s) + ", max=" +
(string) llListStatistics(LIST_STAT_MAX, fps_s) + ", std.dev=" +
(string) llListStatistics(LIST_STAT_STD_DEV, fps_s),
<1.0, 1.0, 0.0>, //yellow
1.0);
11 collapsed lines
}
}
changed(integer change)
{
if(change & CHANGED_REGION)
{
llResetScript();
}
}
}

Given that this operation ignores any non-numbers in a list, it can be used to tell you, in a mixed list, how many of the elements in a list are numbers (when used with the LIST_STAT_NUM_COUNT parameter.)

Original wiki source

Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.

From the Second Life Wiki

Community documentation adapted from LlListStatistics, by Linden Research, Inc. and contributing residents.View contributors and history.

Imported wiki revision:

Licensed under CC BY-SA 3.0. Last wiki edit: .Formatting and links have been adapted for this site; API metadata follows the LSL definitions.