On Wed, Jan 20, 2010 at 2:52 PM, Ricardo . <[email protected]> wrote:
> Thank you for your help!
> By the way, the RandomMlcgC is a better (and slower) random number generator
> because it allows the user to choose the seed that he wants to use?

Both RandomMlcgC and RandomLfsrC are Pseudorandom number generators:
this means that their behaviour is totally deterministic and depend on
the seed they are inited with. A PRNG inited with the same seed will
always give as output the same sequence of numbers. If you're not
familiar with PRNG a good start is of course wikipedia.
http://en.wikipedia.org/wiki/Pseudorandom_number_generator

Both generators use TOS_NODE_ID to build the respective seeds, this
means that by default each generator will output the same sequence on
any node with the same TOS_NODE_ID. RandomMlcgC allows the user to set
his/her own seed, but this function can be easily added to RandomLfsrC
too (check the source code, is quite straightforward).

One of the parameters to measure a PRNG quality is its period, which
is he maximum length of the output sequence before it begins to
repeat. The length of the sequence depends on the PRNG state size.
Since RandomMlcgC's state is 32 bit while RandomLfsrC is 16 bit, the
period of latter  can't be longer than the period of the former.
RandomMlcgC has a period length of 2^31-1 (=2147483647) while
RandomLfsrC can't have a period longer than of 2^16-1 (=65535).

I don't have any supporting evidence, but I can think of two reasons
for RandomMlcgC being slower than RandomLfsrC:

1) RandomMlcgC uses 32 bit integers while RandomLfsrC uses 16 bit
integers - smaller ints mean faster operations;
2) RandomMlcgC is Linear Congruential Generator, a type of PRNG which
requires multiplication modulo N (in this specific case requires a 64
bit multiplication). RandomLfsrC is a Linear Feedback Shift Register,
which is a family of fast PRNG that can be implemented using only
bitwise operators. Multiplications are much much slower than bitwise
operations, and the difference is even bigger if multiplication
operates on 64 bit integers while bitwise operator manipulate 16 bit
integers.

Hope this helps.

Regards.
--
Giuseppe Cardone


> 2010/1/20 Henrik Mäkitaavola <[email protected]>
>>>
>>> I want to generate random numbers, I know that I can use RandomLfsrC or
>>> RandomMlcgC. However, the RandomLfsrC is out of question because it
>>> generates always the same sequence in all nodes.
>>
>> If the nodes have different node id:s both RandomLfsrC and RandomMlcgC
>> should generate different sequences. If the nodes have the same node id both
>> modules will generate same sequences on all nodes because they will all use
>> the same seed.
>>
>> Regarding the built in rand(). I don't know how it is implemented so it
>> may be slower than the once provided by the TinyOS core.
>>
>>
>> 2010/1/20 Ricardo . <[email protected]>
>>>
>>> Thanks for the reply.
>>>
>>> That does not make clear my doubt ... Maybe I have not explained the best
>>> way: there is a method rand() available in the C programming language, which
>>> is also available in TinyOS. This method will not need any wiring or
>>> anything else, it works simply by invoking the function rand().
>>> My question is: what is the difference between this method rand() and
>>> method rand16()/rand32() provided by RandomMlcgC?
>>>
>>> On Wed, Jan 20, 2010 at 2:37 AM, Qiyuan Zhang <[email protected]>
>>> wrote:
>>>>
>>>> Hi, Ricardo.
>>>>
>>>> The interface Random provides two functions: rand16() and rand32().
>>>> RandomLfsrC or RandomMlcgC is the specific implementations. Of course you
>>>> can call functions from them directly. You can also provide your own
>>>> implementation. Interface Random just provides an abstraction layer.
>>>>
>>>> Best wishes
>>>>
>>>> Qiyuan Zhang
>>>>
>>>>
>>>>
>>>> On Wed, Jan 20, 2010 at 5:59 AM, Ricardo . <[email protected]>
>>>> wrote:
>>>>>
>>>>> Hello everyone!
>>>>>
>>>>> I want to generate random numbers, I know that I can use RandomLfsrC or
>>>>> RandomMlcgC. However, the RandomLfsrC is out of question because it
>>>>> generates always the same sequence in all nodes.
>>>>>
>>>>> My question is: what is the difference of using RandomMlcgC instead of
>>>>> calling directly the function rand() (which I do not even know which is 
>>>>> the
>>>>> component that provides the functionality)?
>>>>>
>>>>> I appreciate any explanation.
>>>>>
>>>>> Regards,
>>>>> Ricardo
>>>>>
>>>>> _______________________________________________
>>>>> Tinyos-help mailing list
>>>>> [email protected]
>>>>>
>>>>> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>>>>
>>>
>>>
>>> _______________________________________________
>>> Tinyos-help mailing list
>>> [email protected]
>>> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>>
>
>
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>

_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to