Talk:LlFrand

From Second Life Wiki
Revision as of 13:26, 10 September 2012 by Tanya Avon (talk | contribs)
Jump to navigation Jump to search

Known Issues

1.13.3 specifying mag < 0 always returns 0.

ummm thats not good. I was rather fond of the old method. Why not use the copysign function found in "math.h" after stripping the sign to put it back on? (C99 revisions of glibc will support it aka, won't be in windows but will be in any recent version of linux GCC). Something like:
include <math.h>

float llFrand(float range)
{
    return copysign(new_method(fabsf(range), range);
}
QED Strife Onizuka 18:45, 31 January 2007 (PST)

The issue has already been corrected in the code, unit tested, through QA, and awaiting the next rolling update. Phoenix Linden 08:47, 2 February 2007 (PST)

More Random

How is this any more random? It just substitutes one predetermined sequence of numbers with another... Iain Maltz

I agree with you, it's why I added the needs references. -- Strife (talk|contribs) 09:54, 18 February 2012 (PST)
It is clearly mathematically provable that it is not "more" random. Given the function will have a psuedo-random output that is distributed over a statistical normal curve, any stream of output from the same will result in exactly the same statistical normal curve. Therefore, if we call the bare function f() and the "more random" function f'(), the output will be identically spread out over the same distribution, therefore, f() = f'(). On the other hand, the "more random" function f'() does waste time in a loop.


integer r_seed;
integer f_seed;

//--------------------------//
init() {
vector v;
   v=llGetPos();
   r_seed=llGetUnixTime()+((integer)v.x*(integer)v.y);
   f_seed=r_seed*(integer)(v.x-v.y);
}

//--------------------------//
float tanya_rand(float mag) {
float f;
   r_seed+=2454267026;
   f_seed+=2909493974;
   r_seed=(r_seed<<29)|((r_seed>>3)&536870911);
   f_seed=(f_seed<<27)|((f_seed>>5)&134217727);
   f=(float)llAbs(r_seed)/(float)llAbs(f_seed);
   f-=(float)llFloor(f); 
   f*=mag;
   return f;
}

//--------------------------//
string trim(float num,integer n) {
string txt;
    txt=(string)num;
    return llGetSubString(txt,0,llSubStringIndex(txt,".")+n);
}

//--------------------------//
default {

   //--------------------------//
   state_entry() {
      init();
   }

   //--------------------------//
   touch_start(integer num) {
   integer x;
   string msg;
   float avg;
   float f;

      msg="\n\nllFrand()::\n";
      avg=0.0;
      for (x=0; x<100; x++) {
         f=llFrand(100.0);
         avg+=f;
         msg+=trim(f,3)+" ";
      }
      avg/=100.0;
      msg+="\n\nllFrand() average: "+trim(avg,3);
      llOwnerSay(msg);

      msg="\n\ntanya_rand()::\n";
      avg=0.0;
      for (x=0; x<100; x++) {
         f=tanya_rand(100.0);
         avg+=f;
         msg+=trim(f,3)+" ";
      }
      avg/=100.0;
      msg+="\n\ntanya_rand() average: "+trim(avg,3);
      llOwnerSay(msg);
  
   }

}

-- Tanya Avon 13:26, 10 September 2012 (PDT)

Unclear note

What does mean "the process" in "The sequence of random numbers are shared across the entire process" in Notes. Should one expect it is SIM, object or script "wide" ?—The preceding unsigned comment was added on 18:38, 22 September 2008 by Scarabeus Kurka

By "process" they mean the entire sim. -- Strife (talk|contribs) 07:42, 23 September 2008 (PDT)

Unreferenced?

it's very odd to see the unreferenced template used in a wiki this way... I get why it was put there but there's no reference for internal working of the simulators so it's really out of place... add the fact that it's trying to link to wikipedia and well... can we either fix the template or just note the contentious point (I agree, there's plenty of question just how random [or not] the native function is)?
-- Void (talk|contribs) 19:14, 11 July 2011 (PDT)

  • Well it certainly doesn't make any sense. That's not how entropy works! Adeon Writer 16:14, 17 November 2011 (PST)
  • As to the template, the porting of it from wikipedia turned out to be very involved. -- Strife (talk|contribs) 18:10, 17 November 2011 (PST)