Jump to content

llFrand. Randomness


rasterscan
 Share

You are about to reply to a thread that has been inactive for 1934 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Lets talk about llFrand, shall we ? :)   I was using it to fire random quotes from a list. Then I began to wonder just how even the distribution curve would be over a number set from zero to 10, for example, with 100 sample random number generations.

Here's the script. If you do anything interesting with it please share ! Especially in the way of shrinking it down and tidying it up. 


// llfrand results

integer totalruns;//total script runs
integer zc; //total zeroes
integer ones;
integer twos;
integer threes;
integer fours;
integer fives;
integer sixes;
integer sevens;
integer eights;
integer nines;
integer tens;

default
{
    // reset script when the object is rezzed
    on_rez(integer start_param)
    {
        llSetText("Click to study llFrand(11) \nNumber distribution",<1,1,1>,1);
        llResetScript();
        
    }
 
  
touch_start(integer total_num)


// llPlaySound("beep",1);
llSetText("Running .. ",<1,1,1>,1);
llSetTimerEvent(0.25); 
//totalruns + 1;
} // Every 1 secs


timer() // what to do every .25 secs

integer dicenum = (integer) llFrand(11);  //min 0 max 10 
totalruns++;

if (totalruns == 100){llSay (0, "\n100 runs completed"); llSetTimerEvent(0);llSetText("Click to study llFrand(11) \nNumber distribution",<1,1,1>,1); llResetScript();}
llSay(0, 

"\n-------------------------\nllFrand(11) = " + (string)dicenum +  ". Runs  = " + (string)totalruns + "\n----------------------" +
"\nTotal Zeros  = " + (string)zc + 
"\nTotal   Ones = " + (string)ones +
"\nTotal   Twos = " + (string)twos +
"\nTotal Threes = " + (string)threes +
"\nTotal  Fours = " + (string)fours  +
"\nTotal  Fives = " + (string)fives +
"\nTotal Sixes  = " + (string)sixes + 
"\nTotal Sevens = " + (string)sevens +
"\nTotal Eights = " + (string)eights +
"\nTotal Nines  = " + (string)nines +
"\nTotal Tens   = " + (string)tens
);
//llSleep(0.2);//tiny pause

//WE GOT A ZERO !
if (dicenum == 0) {zc++;} // UP ZC BY 1
if (dicenum == 1){ones++;} //up ones by 1
if (dicenum == 2){twos++;} //up ones by 1
if (dicenum == 3){threes++;} //up ones by 1
if (dicenum == 4){fours++;} //up ones by 1
if (dicenum == 5){fives++;} //up ones by 1
if (dicenum == 6){sixes++;} //up ones by 1
if (dicenum == 7){sevens++;}
if (dicenum == 8){eights++;}
if (dicenum == 9){nines++;}
if (dicenum == 10){tens++;}


} // timer function over

}//scripts done finito ended

 

https://gyazo.com/22f10b6e20d28fdf08aca82e5cfdac4e

 


 

 

 

Edited by rasterscan
Link to comment
Share on other sites

The funny thing about "randomness" and "true random" is that you can't really use statistics to prove how random something is.

If the curve looks like a bell-curve (most values in the range of 2-8), is that random?
If the curve is mostly flat (values evenly distributed across 1-0), is that random?
If you flip a coin an infinite amount of times, will it be exactly 50-50?

In the cases most people use random numbers in, perception is more important than being truly random. In fact, true randomness can be a negative thing.

For example, the random question selection is going to feel bad/boring/annoying if the same question keeps getting picked a lot. To improve the "quality" of randomness, it would be better to keep a record of the most recent questions and never pick those until enough other questions have been picked. This could still lead into some questions not being picked very often, and to prevent that as well, each question's pick count could be tracked and if any question falls below a certain threshold, they would be picked automatically (as long as they also haven't been picked recently).

  • Thanks 2
Link to comment
Share on other sites

2 minutes ago, Wulfie Reanimator said:

 it would be better to keep a record of the most recent questions and never pick those until enough other questions have been picked

Oh I love that idea. And its feasible mathematically I've seen it done in lsl scripting. But I am a mathematics weakling and cannot toss off a 'dont use that number until the other numbers are used once' routine. Although I will mull it over

Link to comment
Share on other sites

3 minutes ago, steph Arnott said:

llFrand is a faux random number.  Over a period it repeats the integer in a pattern. The smaller the range the faster the pattern occures.

ikr. the Rand function has fascinated me for 30 years when I first learnt BASIC. Starts with a 'seed' that much I can just about remember

Edited by rasterscan
Link to comment
Share on other sites

37 minutes ago, rasterscan said:

Oh I love that idea. And its feasible mathematically I've seen it done in lsl scripting. But I am a mathematics weakling and cannot toss off a 'dont use that number until the other numbers are used once' routine. Although I will mull it over

I wrote this years ago for fun

integer card;
list cardlist=[];
integer limit = 10000; // <- bytes This was only for this script.

default
{
    changed(integer ch)
    {
        if(ch&CHANGED_OWNER)
        {
            llResetScript();
        }
    }
    on_rez(integer num)
    {
        llResetScript();
    }
    state_entry()
    {
        llSetMemoryLimit(limit);
    }
    touch_start(integer total_number)
    {
        card = (integer)(llFrand(50));
        if(~llListFindList(cardlist,(list)card))
        {
            llSay(0,(string)card+" You got a match, card number is "+(string)card);

            llResetScript();
        }
        else
        {
            llSay(0,"card number is "+(string)card);
            cardlist += card;
            cardlist = llListSort(cardlist, 1, TRUE);


        }
    }
}

Edited by steph Arnott
  • Thanks 1
Link to comment
Share on other sites

5 minutes ago, rasterscan said:

ikr. the Rand function has fascinated me for 30 years when I first learnt BASIC

Issue is that humans do not choose random numbers. They think they do but they never do. Computers do not either. Mathmatically a true random number is impossible. Also games need to be loaded against the players else it is damned boring to play.

  • Thanks 1
Link to comment
Share on other sites

2 minutes ago, rasterscan said:

cardlist += card;   ... What is the += signifying mathematically ? Please.

 changed(integer ch) ... Wahhh. changed hasn't been declared as a float integer or string. I dont get it. Help ?

It is recording the the number. When two numbers match it returns TRUE. It is so the script can reset. It was only written so i could learn lists.

  • Thanks 1
Link to comment
Share on other sites

30 minutes ago, rasterscan said:

cardlist += card;   ... What is the += signifying mathematically ? Please.

 changed(integer ch) ... Wahhh. changed hasn't been declared as a float integer or string. I dont get it. Help ?

The shorthand operator in "x += y" is equal to saying "x = x + y" Basically, "Add Y to X (and store the result)."

"changed" is a standard LSL event. Basically a function that is called automatically when certain things happen, much like state_entry or touch_start.

Edited by Wulfie Reanimator
Link to comment
Share on other sites

6 hours ago, Wulfie Reanimator said:

The funny thing about "randomness" and "true random" is that you can't really use statistics to prove how random something is.

If the curve looks like a bell-curve (most values in the range of 2-8), is that random?
If the curve is mostly flat (values evenly distributed across 1-0), is that random?
If you flip a coin an infinite amount of times, will it be exactly 50-50?

 

You get into statistics territory here. And yes there is a rule that determines if there is a true randmonness or not. Just not after one run or a few. However, the more often you let the script run and take the average of all results, the closer this average should be to the expected result "10". That's a statistical/mathematical rule. And though it might take several thousand runs, sooner or later the average for each of the numbers should reach a value between 9,9999... and 10.0001...

  • Like 1
Link to comment
Share on other sites

1 minute ago, Estelle Pienaar said:

You get into statistics territory here. And yes there is a rule that determines if there is a true randmonness or not. Just not after one run or a few. However, the more often you let the script run and take the average of all results, the closer this average should be to the expected result "10". That's a statistical/mathematical rule. And though it might take several thousand runs, sooner or later the average for each of the numbers should reach a value between 9,9999... and 10.0001...

Can you link a study on that? Doesn't match any of my understanding of true randomness and I'd love to educate myself.

Link to comment
Share on other sites

Well, it's not so much a "rule" as it is the definition of the mode of an unskewed normal distribution (a bell-shaped curve).  What Estelle is saying is just that if you choose "random" numbers a very large number of times and if they are truly random, then the mean value of all your choices should converge on the mode of a normal distribution.  If it doesn't, then you didn't choose random numbers. 

Link to comment
Share on other sites

https://en.m.wikipedia.org/wiki/Law_of_large_numbers

There is a number of other observations that you can make with "true" randomness. I have never looked into the frant function and can't say if it is "true" randomness or "simulated" randomness. However, if the observations (when it comes to a high number of trials) lead to (almost?) identical results, then it doesn't matter, does it?

You can take the OP's script and change it slightly. Make it 1.000 or 10.000 runs, take the average every run and then see what you get. With 1000 runs I would expect you to "always" end up with anaverage of 9.8 or higher (or 10.2 or lower), with 10.000 runs you should "always" end up with 9.9 or higher (or 10.1 or lower). I am putting always in brackets because if you make a high enough number of such tests you will end up with a deflecting result. It is probability after all. But you can even calculate how high this probability is (thus how many runs you need to get a deflecting result from what I stated above). It's a long time ago that I have made such calculations so I don't feel competent to give a guess, but it should be rather improbable. That's why mathematicians speak of a "law".

  • Like 1
Link to comment
Share on other sites

57 minutes ago, Estelle Pienaar said:

That's why mathematicians speak of a "law".

Law in mathmatics is just a procedure rule. That rule is not immutable.  'random' is philosophical, not a law. Also numbers are only called random with a Kaizon upper and lower limit of what that random scope is used for. Things like online banking access numbers are not random at all. They are a paired algorithm which change when a timer triggers, both seeded with the same start number. Both have to match the paired algorithm result. Random numbers are too easy to crack by another computer. Once it identifies repeats it can copy the funtions output result.

Edited by steph Arnott
  • Sad 1
Link to comment
Share on other sites

3 hours ago, Estelle Pienaar said:

https://en.m.wikipedia.org/wiki/Law_of_large_numbers

There is a number of other observations that you can make with "true" randomness. I have never looked into the frant function and can't say if it is "true" randomness or "simulated" randomness. However, if the observations (when it comes to a high number of trials) lead to (almost?) identical results, then it doesn't matter, does it?

You can take the OP's script and change it slightly. Make it 1.000 or 10.000 runs, take the average every run and then see what you get. With 1000 runs I would expect you to "always" end up with anaverage of 9.8 or higher (or 10.2 or lower), with 10.000 runs you should "always" end up with 9.9 or higher (or 10.1 or lower). I am putting always in brackets because if you make a high enough number of such tests you will end up with a deflecting result. It is probability after all. But you can even calculate how high this probability is (thus how many runs you need to get a deflecting result from what I stated above). It's a long time ago that I have made such calculations so I don't feel competent to give a guess, but it should be rather improbable. That's why mathematicians speak of a "law".

I think you're either wording yourself really poorly, or you've misinterpreted the wiki somehow.

You keep saying "an average of 9.8" or "9.9" or "10," but I have no idea where you get those specific numbers. LLN states that the numbers will tend towards the "expected result" (average), but nowhere does it say any of those numbers you're giving. More specifically, if you throw a 6-sided die an infinite number of time, the average result of all of your throws will get closer and closer to the average of all the possibilities (1,2,3,4,5,6), which is 3.5. But this is just mathematical probability and not a measure of true randomness.

Edit: And, to that effect, llFrand fits right in.

I ran a test of getting "the average of running llFrand(1) 100'000 times", repeated 100 times, then averaging all of the averages.

The lowest average of 100K random numbers was 0.497872 (0.002128 margin)
The highest average was 0.501863 (0.001863 margin)
Total average of all 100 averages was 0.500046

This was my code:

default
{
    state_entry()
    {
        llOwnerSay("going");

        integer k;
        float average_average;
        while(++k <= 100)
        {
            integer i;
            float average;
            while(++i <= 100000)
            {
                average += llFrand(1);
            }
            average /= 100000;

            average_average += average;
            llOwnerSay("average: " + (string)average);
        }

        average_average /= 100;
        llOwnerSay("average of averages: " + (string)average_average);
    }
}

 

Edited by Wulfie Reanimator
  • Like 1
Link to comment
Share on other sites

9 hours ago, Wulfie Reanimator said:

I think you're either wording yourself really poorly, or you've misinterpreted the wiki somehow.

 

English is not my first language and it is a long time ago that I have dealt with all these matters. What I have tried to do is giving you a hint that your bold claim "that you can't really use statistics to prove how random som ething is" is wrong. Yes you can. Or do you think that anyone can come up with a black box function pretending it simulates randomness and no one could prove him/her wrong? Yes you can. You do not even know the law of large numbers but you continue to make bold statements about other peoples' posts.

Edited by Estelle Pienaar
  • Like 2
Link to comment
Share on other sites

24 minutes ago, Estelle Pienaar said:

English is not my first language and it is a long time ago that I have dealt with all these matters. What I have tried to do is giving you a hint that your bold claim "that you can't really use statistics to prove how random som ething is" is wrong. Yes you can. Or do you think that anyone can come up with a black box function pretending it simulates randomness and no one could prove him/her wrong? Yes you can. You do not even know the law of large numbers but you continue to make bold statements about other peoples' posts.

Well i understood what you stated.

  • Like 1
Link to comment
Share on other sites

11 hours ago, steph Arnott said:

Law in mathmatics is just a procedure rule. That rule is not immutable.  'random' is philosophical, not a law. Also numbers are only called random with a Kaizon upper and lower limit of what that random scope is used for.

I know, that's why I put law in quotation marks (which at least in my mother tongue marks that a word is not used it in the typical sense - I am not sure about English and other languages).  😉

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1934 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...