From: TTman on 17 Nov 2009 11:05 "Go Rf" <Rf(a)Rf.org> wrote in message news:4b029fd0$0$272$14726298(a)news.sunsite.dk... > Hello all > > > > I need a function, when called returns a pseudo random number between X > and Y. > > > > I have many boards that periodically broadcasts their board addresses on > an RF link. All boards use the same RF-channel frequency, so data > collisions is going to happen. So I need to randomly delay between those > broadcasts to be able to avoid collisions with other boards broadcasts. > > > > I want to make a pseudo random delay (X ms - Y ms) before sending the > package again. > use the devices address as a delay.... collisions will be random, and so will the address.
From: Arlet on 17 Nov 2009 13:58 On Tue, 17 Nov 2009 14:06:07 +0100, Go Rf wrote: > Hello all > > > > I need a function, when called returns a pseudo random number between X and > Y. > If you have a cheap (enough) 32 bit multiply, this method works pretty well: x(n)=a*x(n-1)+carry Finding a value for 'a' that results in a large period is left as an exercise. > I have many boards that periodically broadcasts their board addresses on > an RF link. All boards use the same RF-channel frequency, so data > collisions is going to happen. So I need to randomly delay between those > broadcasts to be able to avoid collisions with other boards broadcasts. You'll probably also want exponential backoff after detecting a collision. Everytime a board detects a collision (by lack of acknowledgement) it should double the upper bound of its random generator. An easy way to do this is to use an increasing number of bits from your x(n) value above.
From: vladitx on 18 Nov 2009 07:35 On Nov 17, 3:06 pm, "Go Rf" <R...(a)Rf.org> wrote: > I need a function, when called returns a pseudo random number between X and > Y. For the interval [X, Y), assuming _unsigned_ integers and 'C' syntax: random = X + (rnd() % (Y - X)); Where "rnd()" is your source of pseudo-random unsigned integer. Choosing that is however dependent on your resources and expectations.
From: Hans-Bernhard Bröker on 18 Nov 2009 08:30 vladitx wrote: > On Nov 17, 3:06 pm, "Go Rf" <R...(a)Rf.org> wrote: > >> I need a function, when called returns a pseudo random number between X and >> Y. > > For the interval [X, Y), assuming _unsigned_ integers and 'C' syntax: > > random = X + (rnd() % (Y - X)); An elegant formula, isn't it? Unfortunately it has a serious problem: the result doesn't have the qualities usually requested from it. It's not uniformly distributed unless (Y-X) just so happens to exactly divide the range of the random number generator. Otherwise you get (RND_MAX+1)%(Y-X) outcomes that are more probable than the others.
From: Ari Okkonen on 18 Nov 2009 14:17 Recommended reading: Donald Knuth: Art of Computer Programming, part: Seminumerical Algorithms BR Ari Go Rf wrote: > Hello all > > > > I need a function, when called returns a pseudo random number between X and > Y. ....
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: OpenOCD+GDB (stepi. Unable to single step) Next: Compact Flash IDE PIO Write Size Issues |