int select_this (int p) {
/* generate a new random integer in the range 0...4294967295 */
unsigned int r = random ();
/* the floating point equivalent of the maximum possible integer */
float maxint = 4294967295.0;
/* a floating point random number integer in the range 0...1 */
float fr = ((float) r) / maxint;
/* return true with probability p / 100. Since fr is evenly
distributed in the range 0..1, the likelyhood that it is less
than p is proportional to p/100. */
return (fr < (((float) p) / 100.0));
}
The following pseudo-code shows how to decide whether to send the
packet, drop it, or send it in duplicate. The packet and p are
assumed to be parameters to a function send, which is called
whenever we want to send a packet (be it a data segment, and ack,
or a packet carrying a new window).
... send ( ... packet, int p) {
if (select_this (p)) { /* random selection */
/* do nothing, i.e. discard packet */
} else if (select_this (p)) { /* a new random selection */
send the packet, and
send the packet again
} else {
send the packet
}
}
Although this is C code, it should be easy to recode in whatever
language you have chosen.
A server implementing idempotent operations can be a stateless server.


.... x = f_stub (3, "a"); ....The stub for f has code along these lines:
int f_stub (int a, char * c) {
char b [BUFSIZE];
represent_int (a, b, 0);
n = 4 + represent_string (c, b, 4);
s = socket (...
connect (s, ...
send (s, b, n);
recv (s, b, BUFSIZE);
return decode_int (b);
}
