Random number generration in Omnet++ - omnet++

I uniformly distributed the sensor nodes using
intuniform (0,1000);However,everytime when I started the simulation from beginnig, all the sensor nodes is placed at the same position.Then I used the srand(time(NULL)) the result is again same.For example, in the first run sn[1] position is
(150, 167), it is same in the second run.I want to change it.The program should not memorize it.Thanks for your help.

OMNeT++ uses different pseudo random number generators than standard C++. It is a core feature of OMNeT++ that running the same simulation twice yields exactly the same result. The function srand changes the seed of the standard C++ generator only. You can also change the seed of OMNeT++ generators, but more likely you want to start a different run of your simulation. This will automatically use a different (well chosen) seed.

Related

How to create/generate vehicles from veins instead of SUMO

Currently, I am generating vehicles from SUMO and importing into veins. However, now I want to use large number of vehicles (from 100 to 1000) and I want their random generation (e.g., random start time and random speed).
Can anyone help that i) how can I create/generate vehicles from veins instead of SUMO? and ii) how to randomly select start time and speed of vehicles?
Best Regards,
Yasir
This is what https://github.com/sommer/veins/blob/veins-5.1/src/veins/modules/mobility/traci/TraCIVehicleInserter.ned was designed for. Whenever the number of active vehicles in OMNeT++ is less than a configured number, it starts a new vehicle using one of the existing route definitions.
You can use python to generate route files with random seed/random start time.
Refer to runner.py file in https://github.com/eclipse/sumo/blob/master/tests/complex/tutorial/traci_tls/runner.py and to the tutorial in https://sumo.dlr.de/docs/Tutorials/TraCI4Traffic_Lights.html

Generating Random Number AVR without seed

I writing an application in AVR Studio 4 which generates random numbers and outputs them on a seven segment display. At the moment i am using a seed, the seed value then gets randomized and the value output. This method obviously produces the same random number sequence (and displays the same sequence) every time the program is run. Is there an alternate method i can use which does not use a seed and as such does not start the program with the same number each time, allowing for different random numbers.
Thanks
Each time the microcontroller starts up it is seeing exactly the same internal state as any other time it starts up. This means its output will always be the same regardless of any algorithm you might use.
The only way to get it to produce different behaviour is to somehow modify its state at startup by introducing some external information or by storing state between startups. Some ideas for how to do the first option might be to measure the duration of a user key press (if your system has buttons) or sensing a temperature or other external input and using this to seed the algorithm. However the simplest option is probably to just store a counter in EEPROM that is incremented after each startup and use this to generate the seed.

Generate on/off signals of random duration SIMULINK

For my SIMULINK model I need to generate a signal that takes the values 1 or 0. To generate it I need to draw a number from a an exponential distribution and use this number as the time the signal stays in 0. Once this time has passed, I have to draw a new number from the exponential distribution and use this number as the time the signal stays in 1, and the repeat the process until the end of the simulation. As a SIMULINK newbie I'm quite puzzled by this problem and would appreciate any suggestions on how to solve it.
You've got a couple of choices.
In MATLAB, you can generate all samples in advance (i.e. before running the simulation) and use them to create a suitable signal, then use that as an input into the model (using the From Workspace block).
Or, if you need to do the sampling at each time step, then you have to write an S-Function, using the random number in the mdlGetTimeOfNextVarHit method. There is an example of doing something very similar on the Goddard Consulting web site called Square Wave with Jitter.

What is a seed in relation to a random number generation algorithm and why is computer time used to create this seed more often than not?

I read that seeds are used to initialize random number generators. But seems like the randomness of the seed doesn't matter much for getting good randomness from the generator. So I want to understand what is a seed actually? Why is it called so? And lastly why time in a computer system is used to generate such seeds?
A pseudo-random number generator produces a sequence of numbers. It isn't truly random, but generally a mathematical calculation which produces an output that matches some desirable distribution, and without obvious patterns. In order to produce such a sequence, there must be state stored for the generator to be able to generate the next number in that sequence. The state is updated each time using some part of the output from the previous step.
Seeding explicitly initialises this state. A 'seed' is a starting point, from which something grows. In this case, a sequence of numbers.
This can be used either to always generate the same sequence (by using a known constant seed), which is useful for having deterministic behaviour. This is good for debugging, for some network applications, cryptography, etc.
Or, in situations where you want the behaviour to be unpredictable (always different each time you run a program, a card game perhaps), you can seed with a number likely to be continually changing, such as time.
The 'randomness' of the sequence does not depend on the seed chosen, though it does depend on not reseeding the sequence.

Make CURAND generate positive different random numbers less than a specific number

I am trying to use CURAND library to generate random numbers which are completely independent of each other. Hence I want to give different seeds to each thread.
So, Question 1: How do I give different seeds to each thread?(Is there some time function in CUDA which I can use?)
Now I also want to generate this random number between a range i.e 0 to 10000. How do I accomplish that to happen.
Currently I am using curand_normal (as I want to have numbers from normal distribution) but its giving me negative and same numbers which I do not want.
Setting different seeds is not a statistically sound way to get independent (non-correlated) random numbers (with any single random number generator). You would be better off selecting different sub-sequences of a single sequence, and most random number libraries will allow you to do that, including cuRAND.
Check out the examples in the CUDA SDK, for example the EstimatePiP or EstimatePiInlineP examples use cuRAND to generate pseudo-random numbers.
For the second part of your question, as mentioned in the cuRAND manual the curand_normal() routines return Normally distributed numbers with mean 0.0 and standard deviation 1.0 (i.e. Standard Normal Distribution). Clearly that means that you will have ~50% negative numbers.
It doesn't make sense to specify a fixed range along with the Normal distribution. You either want some other distribution (e.g. Uniform) with the fixed range or else you want the Normal distribution with a specific mean and standard distribution. To get from the Standard Normal to your target mean/std.dev. you simply multiply the random draw by the target standard deviation and add the target mean.

Resources