Timer.getNow() starts over at zero after every boot, so you’re probably using 
the same seed every time unless something during the boot process takes a 
variable amount of time (and on an embedded system or in the simulator, it 
probably takes the same amount of time, every time – at least down to the 
millisecond level).
Michiel

From: tinyos-help-boun...@millennium.berkeley.edu 
[mailto:tinyos-help-boun...@millennium.berkeley.edu] On Behalf Of Jisha Mary 
Jose
Sent: Thursday, July 10, 2014 11:18
To: Eric Decker
Cc: Tinyos Help Request; Tinyos-Help
Subject: Re: [Tinyos-help] random number

I did that, i changed the seed. But still same numbers are generated again and 
again at a particular node.

Regards,

Jisha Mary Jose
......jMj......

On 10 July 2014 13:05, Eric Decker 
<cire...@gmail.com<mailto:cire...@gmail.com>> wrote:

asked and answered.

The random number generator is pseudo-random.

It starts up using a SEED which you need to modify to get different sequences.


On Wed, Jul 9, 2014 at 11:52 PM, Jisha Mary Jose 
<jishamary1...@gmail.com<mailto:jishamary1...@gmail.com>> wrote:
Hi,
I have to generate random number for a node to use in key generation. But i 
always get the same random number. So ichanged seed value using the current 
system time as shown below.

module SecurityC{

    uses interface Boot;
    uses interface Random;
    uses interface ParameterInit<uint16_t> as SeedInit;
    uses interface Timer<TMilli>;
}

implementation{

    uint32_t rand1;
    uint32_t t;

    event void Timer.fired() {

         t=call Timer.getNow();
        dbg("Boot", "%s Current time: %d \n", sim_time_string(), t);
    }

    event void Boot.booted()
    {

        dbg("Boot", "Application booted.\n");
        t=call Timer.getNow();
        call SeedInit.init(t);

        rand1 = (call Random.rand32()%10)+7;

        dbg("Boot", "%s Random number 1: %d \n", sim_time_string(), rand1);

    }
}
But still i am getting the same number always. How to solve this?
Regards,

Jisha Mary Jose
......jMj......

_______________________________________________
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu<mailto:Tinyos-help@millennium.berkeley.edu>
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help



--
Eric B. Decker
Senior (over 50 :-) Researcher

_______________________________________________
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to