How to use current time in seed number of ELM random - random

Random seed in Elm programming. If I use fixed seed I will get same random number. How can I use current time in seed number? I am using Elm 0.19.
Random.initialSeed <currentTime>
So - how to get current time or start time to ?

You can use Time.now to get a Task which can produce the current time, or Time.every to subscribe to time updates.
However, if you're just trying to avoid having your random values be predictable, you will want to use Random.generate, which produces a Cmd which will trigger a message with the generated value. This prevents you from having to deal with Seed values.

Related

Understanding random number generation

I'm creating a game where I want to create random worlds and give the player the option of having the same world made again by entering the same seed...
So... How can I do this? It will generate the same set of numbers, but not the same every time you call for the random function...
Do I have to make function of sorts based on the seed manually?
In GameMaker Studio and GameMaker 8.1 there is a function:
random_set_seed(seed)
Here you can enter your seed.
Then random(x) gives the same n-th result per game run.
random(100)
randomize() // This doesn't change rand[0] or rand[1]
random_set_seed(20) // because of this
rand[0]=random(100)
rand[1]=random(100)
Randomizer functions either use mathematical formulas which seem to give out random numbers or just look at an already calculated array of seemingly random numbers and return them in order. In most languages, there is a function which will look at the computer's clock and will use this value as a first value for the mathematical formula or as a starting index in the pseudorandom array. In GameMaker, you can use randomize() to do that. Only call that once when the game launches and you'll get different results on every execution.
If you want the opposite, that is you want to be able to regenerate the same seemingly random sequence, you can instead set the seed manually with random_set_seed(value). The value passed needs to be a number. Then you can give that seed to the player.
So if you want to generate a random level on the first time and later be able to replay the same level, you need to do in order:
Call randomize to set a random seed.
Call random_get_seed which will return the current seed.
Call random and the likes to generate a level.
When the player wants to use the same seed as before, call random_set_seed and pass it the seed.
Warning: By using those functions, you are putting your trust in GM's randomizing functions. These are platform dependent, and the functions might change in a later version of GM. If you want your seeds to work across all platforms and versions of your game, you might want to work on your own randomizing functions.

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.

Can't understand why I need to seed using srand

When we need a random number we use srand once to initialize the seed and after that we can use rand. Why do we need to seed using srand? For example srand(time(Null)); Can't we just use rand() % 99999? Am I missing something in the concept of these functions?
Here's the thing,
You actually don't need to seed your random number generator. Go ahead, try it without!
BUT, you will always get the same sequence of 'random' numbers.
Pseudo-random number generators such as rand() only generate random-looking sequences. If you just start them from the 'beginning' every time, they will of course look the same.
Seeding the generator is a good way to get numbers that actually appear 'properly' random. If you seed with the time, you are starting somewhere 'random' in the sequence. Note that picking time values close together usually gives two sequences that are also very different.
You can seed with whatever you like. For example, if you have lots of threads using lots of generators, the time is a bad idea because the time may well be the same for multiple threads.
There is no clear 'good' value for the seed, so it is usually not seeded by default. This can also be a good thing if you want to 're-run' a randomised algorithm with exactly the same input: just set the seed to be the same seed.
srand(0) will always return the same deterministic sequence of values, although those values will appear random.
Knowing your seed will allow an attacker to determine every number you generate.
By setting a seed, you effectively create a different sequence.
srand(0) may be entirely acceptable to your needs, if you only need the appearence of random.

What are the available value(s) for "seed for Randome Function" used in JMeter for Random Variable config Element

Need to know what are the available value(s) for "seed for Random Function" used in JMeter for Random Variable config Element.
(It would be better with examples)
A seed is a value used to generate random output on. As a random number function is really just a function, the "random" value being output is always based on the seed. In other words, if you seed the random output generator with the same seed value, you will get the same "random" result. This is why most random number generators use the system time to seed themselves, as that is highly variable.
Now back to your question. If you specify a seed, you will get fixed random output. This makes it easy for you to repeat the test with the exact same random values, just pass in the same seed.

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.

Resources