swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

help with random numbers and seeding?


From: owner-swarm-support
Subject: help with random numbers and seeding?
Date: Thu, 18 Feb 1999 19:24:42 -0700 (MST)
Date: Thu, 18 Feb 1999 18:21:10 -0800

Greetings SWARM folks, 

I'm currently putting together a simple program that explores random
number generation. I've put together the following code:

==== begin ====

//main.m

#import <simtools.h>
#include <stdlib.h>
#import <random.h>

int

main(int argc, char ** argv)
{
        int i;
        int maxAge = 10;
        int age = 0;
        
        initSwarm(argc, argv);
        
        while(age < maxAge) 
        {
                age++;
                printf("Hey, the random number is %d \n",
[uniformIntRand getIntegerWithMin: 0 withMax: 100]);            
        }
        
        return 0;
}

==== end ====

Indeed, I get a list of random numbers, but they appear to be
pseudo-random. That is, the same sequence results each time I run the
compiled application.

My questions are:

1) Is this the best (or, at least, not worst) way to 'pull' a number
from a uniform distribution? Eventually, I'd like to pull a number
between 0 and 1 that I can use for simulating stochastic events.
2) What is the best way to seed the RNG so that I get a different
sequence of numbers each time I run the application?
3) Is there a super great place to read up on the random.h library? In
particular, something accessible to a newbie that would have
illustrative code?

Cheers,

Joseph Villa



                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]