Re: Signature

Troy Piggins <[email protected]>
Newsgroups gmane.network.slrn.user
Message-ID <[email protected]>
* Ivan Popovski is quoted & my replies are inline below :
> On Fri, Feb 22, 2008 at 01:55:48PM +0100, Ivan Popovski wrote:
> > Huh ok found anomaly here. RANDOM is acting silly here cause it gives
> > same number (same signature) in whole slrn session (you must exit slrn
> > if you want to get other signature lol). You should think of other
> > way to get random number i guess :) or somehow force RANDOM to change
> > values every time you try to post :) 
> 
> Doh its not RANDOM problem its logical problem, i rewrite "signature"
> variable, and after that it doesnt have '|' lol. I ll play with that this
> weekend :)

Rather than using the bash special function $RANDOM, JED showed me this little
trick for generating random numbers for one of my macros recently.  Current
s-lang version does not have a random number generator function, but I
understand it will be included in an upcoming release.

#v+
% Pseudo-random function provided by John E Davis on the slang-users mailing
% list, because from what I can tell at the time of writing this there is no
% way of generating random numbers in s-lang without the gsl module which most
% people won't have.  Possible in slang 2.1.4.

private variable Random;
define srandom (r)
{
   Random = r;
}
srandom (_time() * getpid());
define random ()
{
  Random = (Random*69069U + 1013904243U)&0xFFFFFFFFU;
  return Random;
}
% end pseudo-random function
#v-

Then in your function, use it like this

#v+
define your_function()
{

...
   % returns random number between 0 and 999
   variable rnd=  random() mod 1000;
...

}
#v-

-- 
Troy Piggins | http://piggo.com/~troy/slrn                    ___  |   __   __
                                                             |___  | |/   |/  |
* Updated macro: 14/2/08 - create_msg_id.sl                   ___| | |    |   |
                           now includes random char generation           

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.