Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

RajVerma (Programmer) (OP)
25 Aug 04 5:20
hi all,

I used the Random Number Generator, page 85, from the book "Practical Programming in Tcl and Tk(3rd edition)" by Brent B. Welch. As it is mentioned there, it was adapted from a different source. anyway, the point is this RNG is having a flaw. It took me one whole day to recognize this as my program was giving some bizzare results. finally I found out that this RNG is generating repeated sequence of random numbers.

for example if I use this RNG to produce ten random numbers between 1 and 10, and if I call the same routine for 300 times, that means I get 300 number sequences of ten numbers per each sequence. these sequences are getting repeated after a while, like 100th sequence is same as 240th, 101st sequence is same as 241st and so on.

My request is can anyone tell me where I can get a better RNG to use in my Tk script.

thnx in adv,
Raj.
fl0ra (MIS)
26 Aug 04 9:56
again...
tcllib would be very useful for that:

CODE

package require math
::math::random

::math::random ?value1? ?value2?
Return a random number. If no arguments are given, the number is a floating point value between 0 and 1. If one argument is given, the number is an integer value between 0 and value1. If two arguments are given, the number is an integer value between value1 and value2.
fl0ra (MIS)
26 Aug 04 10:00
or

CODE

package require math::statistics



::math::statistics::random-normal mean stdev number
Return a list of "number" random values satisfying a normal distribution with given mean and standard deviation.
mean - Mean value of the distribution
stdev - Standard deviation of the distribution
number - Number of values to be returned



::math::statistics::random-exponential mean number
Return a list of "number" random values satisfying an exponential distribution with given mean.
mean - Mean value of the distribution
number - Number of values to be returned



::math::statistics::random-uniform xmin xmax value
Return a list of "number" random values satisfying a uniform distribution with given extremes.
xmin - Minimum value of the distribution
xmin - Maximum value of the distribution
number - Number of values to be returned
marsd (IS/IT--Management)
29 Aug 04 11:19
Or even better:

CODE

proc randnum{num} {
 set rnum [expr {int(1 + rand() * $poss)}]
 return $rnum
}
wilsoj2 (Programmer)
24 Sep 04 19:20
static const long A = 48271L;
static const long M = 2147483647L; //2^31 -1
static const long Q = M / A;
static const long R = M % A;

unsigned long
Random::RandomLong( )
{
  long TmpSeed = A * ( Seed % Q ) - R * ( Seed / Q );
  if( TmpSeed >= 0 )
    Seed = TmpSeed;
  else
    Seed = TmpSeed + M;
  
  return Seed;
}

Xi+1 = A(Xi(mod Q))-R[Xi/Q]+Mdel(Xi)

All of this is taken from:
Algorithms, Data Structures, and Problem Solving with C++, by Mark Allen Weiss

He also discribes rand functions for different distributions you may or may not be looking for.  (gaussian as above,  poisson, etc)

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close