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?
skiing
0
Newbie Poster
Recommended Answers
Jump to Postwell 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?
Jump to Postso what is n and where are high and low used for your range checking?
All 5 Replies
NathanOliver
429
Veteran Poster
Featured Poster
skiing
0
Newbie Poster
NathanOliver
429
Veteran Poster
Featured Poster
wildgoose
420
Practically a Posting Shark
kvprajapati
1,826
Posting Genius
Team Colleague
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.