samedi 20 février 2021

I want to enter two values in type __int64 and get a random value between them. in VC6.0

I am currently using the contents below and I want to get a bigger number. If possible, I want to modify the source rather than explain it. Because I don't know much about programming. ... Programming is difficult, but English is more difficult........... Again, in VC6.0

#define m  (unsigned long)2147483647
#define q  (unsigned long)127773

#define a (unsigned int)16807
#define r (unsigned int)2836

static unsigned long seed;

void srandom(unsigned long initial_seed)
{
    seed = initial_seed; 
}


unsigned long random(void)
{
   register int lo, hi, test;

    hi   = seed/q;
    lo   = seed%q;

    test = a*lo - r*hi;

    if (test > 0)
    seed = test;
    else
    seed = test+ m;

    return seed;
}

int number(int from, int to)
{
  if (from > to) {
    int tmp = from;
    from = to;
    to = tmp;
  }

  return ((random() % (to - from + 1)) + from);
}



Aucun commentaire:

Enregistrer un commentaire