Re: AOLS Stats: 13/01/2006-12/02/2006



On Tue, 14 Feb 2006, houghi <houghi@xxxxxxxxxxxxxxxxxx> wrote:-

David Bolt wrote:
I wanted to get a random number, so the version would be different each
time. Unfortunatly my prgramming skills are not that good. Having a
different program each time I post would also be a neat idea. :-)

If that's all you're after, this patch should easily do that:

Thanks. I always forget how to apply a patch.

man patch :)

+ myrand1=rand() % 1000;
+ sprintf(myrand2,"0.%u.%u.%u",myrand1/100,(myrand1/10)%10,myrand1%10);

Mmm. Trying to understand what is going on here. I don't quit get it. I
understand that "0.%u.%u.%u" will end up with "0.x.y.z" I don't
understand the rest. I asume myrand1/100 does the x, (myrand1/10)%10
does the y and myrand1%10 does the z, but why are they different?

Simple explanation:

Assume, just for this example that myrand1=109.

myrand1/100 returns just what it says but, since it's an integer,
mrand1/100 would give you 1.

The second expression, (myrand1/10)%10, divides myrand1 by 10, and then
the "%" means divide again, but this time return the remainder, which
would be 0.

The last expression, myrand1%10, means divide by 10 and return the
remainder, which would be 9. So, for myrand1=109, you'd get a version
string of 0.1.0.9.

The initial assignment, myrand1=rand() % 1000; gets a random number,
anywhere between 0 and 2147483647, divides it by 1000 and then assigns
the remainder to myrand1.

+ post_printf (fcc_fp,
+ "X-Newsreader: slrn/%s\nX-Theaboveline: is
not quite right.\n\n",
+ myrand2);

OK. This is clear and fun can be had with that. Random OE versions. :-)

Possible, but the format would be slightly different, and myrand2 would
need to be a bit bigger.

Random phonenumbers.

That I don't think would be quite such a good idea.

X-Usenet-police: 1-800-555-7726
(The above was NOT a random number
http://www.nomeaning.net/phonewords.php will give some insight.)

Actually, I have noticed I missed something out. I didn't call srand()
to seed the random number generator and, each run through will generate
the same sequence of numbers. This new version of the patch, which
you'll need to apply to the original post.c, reseeds the random number
generator with the present time, so each sequence should be
different[0].

----- Start of patch -----
*** ../../slrn-0.9.8.1.orig/src/post.c Tue Feb 14 10:12:11 2006
--- post.c Tue Feb 14 21:44:25 2006
***************
*** 1290,1300 ****
--- 1290,1308 ----
int has_messageid = 0;
char *system_os_name;
char *responses;
+ static int myrand1=0;
+ char myrand2[32];
+
+ if(!(myrand1))
+ srand((int)time(NULL));

system_os_name = slrn_get_os_name ();

try_again:

+ myrand1=rand() % 100000000;
+ sprintf(myrand2,"7.%02u.%04u.%04u",myrand1/1000000,(myrand1/1000)%1000,myrand1%1000);
+
perform_cc = 0;

if (Slrn_Batch == 0)
***************
*** 1463,1470 ****
--- 1471,1484 ----
slrn_mime_add_headers (fcc_fp);
}
#endif
+ /*
post_printf (fcc_fp, "User-Agent: slrn/%s (%s)\n\n",
Slrn_Version, system_os_name);
+ */
+ post_printf (fcc_fp,
+ "X-Newsreader: Micro$oft Outlook Express %s\nX-Theaboveline: is not quite right.\n\n",
+ myrand2);
+
header = 0;
#if SLRN_HAS_MIME
if (Slrn_Use_Mime & MIME_DISPLAY) vp = slrn_mime_encode (vp);
----- End of patch -----


[0] Unless you manage to start multiple copies at the same time.

Regards,
David Bolt

--
Member of Team Acorn checking nodes at 50 Mnodes/s: http://www.distributed.net/
AMD1800 1Gb WinXP/SUSE 9.3 | AMD2400 256Mb SuSE 9.0 | A3010 4Mb RISCOS 3.11
AMD2400(32) 768Mb SUSE 10.0 | RPC600 129Mb RISCOS 3.6 | Falcon 14Mb TOS 4.02
AMD2600(64) 512Mb SUSE 10.0 | A4000 4Mb RISCOS 3.11 | STE 4Mb TOS 1.62
.



Relevant Pages

  • Re: Order modulo p^n (Number Theory)
    ... order via theorems and was getting know where. ... After that I used Newtons binomial and showed that p^n divides all the ... powers less than n-1 the expansion dosent give the remainder 1 and the ... what am I missing here? ...
    (sci.math)
  • Re: prime number routine
    ... > need a routine for figuring out if a number inputted by the user is a prime ... and the number itself which divides that number evenly. ... it is very clear, that if such a potential divisor exists, it cannot be ... In no case were we left with a remainder of 0, ...
    (comp.lang.cpp)
  • Re: Modular Exponentiation?
    ... Be aware that you are using "mod" as an operator; in mathematics, ... Since N divides both ac-bc and bc-bd, then N divides the sum, ... let t be the remainder of dividing X by N. Then your "X mod N" ...
    (sci.math)
  • Re: noob question: easiest way to parse an int?
    ... remainder of 930, i would have the "2nd" digit. ... divides by 10 although converting to string is not a horrible choice. ...
    (comp.lang.java.programmer)