Csound Csound-dev Csound-tekno Search About

[Cs-dev] Inconsistency in seed for randh and randi

Date2007-03-17 21:42
FromAndres Cabrera
Subject[Cs-dev] Inconsistency in seed for randh and randi
Hi all,
I've noticed an inconsistency between the documentation and the source
for randh and randi. The manual states for the iseed argument:

A value between 0 and +1 will produce an initial output of /kamp *
iseed./ A value greater than 1 will be used directly, without scaling. A
negative value will cause seed re-initialization to be skipped. The
default seed value is .5.

However in the source code (See function rhset from Oops/ugens4.c), if
the iseed value is greater than 1, the opcode seeds from current time.
I've fixed a scaling problem reported in vrandh, and wanted to give it
functionality similar to randh.

What should be done? Should the code be preserved, and the manual
changed, or should a value of 1 be used for seeding from current time?

Cheers,
Andrés


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2007-03-18 11:33
Fromjpff
SubjectRe: [Cs-dev] Inconsistency in seed for randh and randi
The words say BETWEEN 0 and +1 one thing happens
Values GREATER that 1 another thing happens
For the value EXACTLY 1 a third thing happens.

Do not see the problem

==John ffitch

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2007-03-18 12:47
FromAndres Cabrera
SubjectRe: [Cs-dev] Inconsistency in seed for randh and randi
Hi,
Yes, that's what the manual says. But the source code does something
different. If the value is greater that 1 it will not use the seed value
unscaled, it will seed from current time. If the value is negative, it
will not cause seed re-initialization to be skipped. There's also the
check for (ss>FL(1.0)), which will never be true. So with the code as it
is is somewhat buggy and does not comform with the manual.

Should I just change the manual to the current action and forget the
whole thing?

Cheers,
Andrés

from Oops/ugens4.c:

int riset(CSOUND *csound, RANDI *p)
{
    p->new = (*p->sel!=FL(0.0));
    if (*p->iseed >= FL(0.0)) {                       /* new
seed:            */
      if (*p->iseed > FL(1.0)) {    /* As manual suggest sseed in range
[0,1] */
        unsigned long seed;         /* I reinterpret >1 as a time seed */
        seed = csound->GetRandomSeedFromTime();
        csound->Message(csound, Str("Seeding from current time %lu\n"),
seed);
        if (!p->new) {
          short rand = (short)seed;
/*           short ss = rand; */
          /* IV - Jul 11 2002 */
          p->num1 = (MYFLT)(rand) * DV32768; /* store num1,2 */
          rand *= RNDMUL;         /*      recalc random   */
          rand += 1;
          /* IV - Jul 11 2002 */
          p->num2 = (MYFLT)(p->rand=rand) * DV32768;
/*           printf("seed, rand, num1, num2 = %d(%x), %d*%x), %f, %f\n", */
/*                  ss,ss,p->rand, p->rand, p->num1, p->num2); */
        }
        else {
          p->rand = randint31((long) (seed % 0x7FFFFFFEUL) + 1L);
          p->rand = randint31(p->rand);
          p->num1 = (MYFLT)(p->rand<<1) * dv2_31; /* store num1,2 */
          p->rand = randint31(p->rand);
          p->num2 = (MYFLT)(p->rand<<1) * dv2_31;
        }
      }
      else if (!p->new) {
        short rand = (short)(*p->iseed * FL(32768.0)); /* init rand integ */
        rand *= RNDMUL;                 /*      to 2nd value    */
        rand += 1;
        p->num1 = *p->iseed;                    /*      store num1,2    */
        p->num2 = (MYFLT)rand * DV32768;        /* IV - Jul 11 2002 */
        p->rand = rand;
      }
      else {
        MYFLT ss = *p->iseed;
        if (ss>FL(1.0)) p->rand = (long) ss;
        else p->rand = (long) (*p->iseed * FL(2147483648.0));
        p->rand = randint31(p->rand);
        p->rand = randint31(p->rand);
        p->num1 = (MYFLT)(p->rand<1) * dv2_31; /* store num1,2 */
        p->rand = randint31(p->rand);
        p->num2 = (MYFLT)(p->rand<<1) * dv2_31;
      }
      p->phs = 0;                               /*      & clear phs     */
      p->dfdmax = (p->num2 - p->num1) / FMAXLEN;  /* & diff     */
    }
    p->ampcod = (XINARG1) ? 1 : 0;      /* (not used by krandi) */
    p->cpscod = (XINARG2) ? 1 : 0;
    return OK;
}
jpff wrote:
> The words say BETWEEN 0 and +1 one thing happens
> Values GREATER that 1 another thing happens
> For the value EXACTLY 1 a third thing happens.
>
> Do not see the problem
>
> ==John ffitch
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
>
>   


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net