I am really confused on this problem someone please assist me I am suppose to create a random number generator that passes in a high and low value and return a random number using a generator that is not biased. It makes use of the idea of cuttoff. I know there are better generators but I have to use this one Here is the code that I have.
long randint(long low, long high)
{
s=MAX/(n+1);
cutoff=s*(n+1);
while((r=rng()) >= cutoff)
;
p=r/s;
}
I don't understand what the p value does and from this how do you get the random number your looking for in the range low to high?

Recommended Answers

All 5 Replies

well the values s, cutoff and p are are not being declared. secondly what is the function rng()? also where are you using high and low?

Those variables are declared I just put the puedocode in my post. The namespace is declared already and the rng() is the range of numbers it can be in

so what is n and where are high and low used for your range checking?

here's a leg up....

if (low > high)
{
   long t = low;
    low = high;
    high = t;
}

range = high - low + 1;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.