As I'm trying to write a random hero function in the WC3 Map Editor I've discovered that the built in GUI code for generating a Random number is not so random. Its a disgusting repeating Pseudo Random line. Every time the trigger is run it generates the same sequence of numbers no matter how many times the trigger is ran.
Is there a way to generate a more random looking set of numbers?
Actions
-Set randomInt[(Player number of (Owner of (Sold Unit)))] = (Random integer number between 1 and 10)
-Game - Display to (All Players) the text: (String(randomInt[(Player number of (Owner of (Sold Unit)))]))
I have no problem with the Pseudo Random concept, but it doesn't generate a new line of Pseudo Random whenever the game starts. Now my real problem is that I'm deployed in Afghanistan and all of the WC3 Map Making communities are blocked. Does anyone know how to generate a more random sequence of numbers?
According to this thread:
That only happens when you play the
map through the "test map" feature in
the world editor. It will always
generate the same variables, even if
random. If you really want to test
triggers with random
variables/numbers, play the map
normally by opening wc3 and selecting
the map in-game.
there is a setting in the map editor for that, generate random by using same seed.
Related
I'm trying to write a program that requires me to generator a random number.
I also need to make it so there's a variable chance to pick a set range.
In this case, I would be generating between 1-10 and the range with the percent chance is 7-10.
How would I do this? Could I be supplied with a formula or something like that?
So if I'm understanding your question, you want two number ranges, and a variable-defined probability that the one range will be selected. This can be described mathematically as a probability density function (PDF), which in this case would also take your "chance" variable as an argument. If, for example, your 7-10 range is more likely than the rest of the 1-10 range, your PDF might look something like:
One PDF such as a flat distribution can be transformed into another via a transformation function, which would allow you to generate a uniformly random number and transform it to your own density function. See here for the rigorous mathematics:
http://www.stat.cmu.edu/~shyun/probclass16/transformations.pdf
But since you're writing a program and not a mathematics thesis, I suggest that the easiest way is to just generate two random numbers. The first decides which range to use, and the second generates the number within your chosen range. Keep in mind that if your ranges overlap (1-10 and 7-10 obviously do) then the overlapping region will be even more likely, so you will probably want to make your ranges exclusive so you can more easily control the probabilities. You haven't said what language you're using, but here's a simple example in Python:
import random
range_chance = 30 #30 percent change of the 7-10 range
if random.uniform(0,100) < range_chance:
print(random.uniform(7,10))
else:
print(random.uniform(1,7)) #1-7 so that there is no overlapping region
Given a sequence (ex 1 4 3 5 3 6 .....) and its range (ex 1-10 ), knowing that it is generated from a "Random Generator".
How to know whether that "Random Generator" is pseudo random or true random (Assuming the sequence is infinite).
Obviously, you can't. For one thing -- the only thing you can actually observe is a finite sequence of numbers. Every possible observed sequence will have a non-zero probability of occurring even if the sequence is genuinely random. You can observe 20 tails in a row and that is completely consistent with tossing a genuinely fair coin. Conversely, any finite sequence, no matter how random it looks, can be generated by a deterministic process.
Having said that, there are various statistical tests (most famously the Diehard tests developed by George Marsaglia) which can be applied to a sequence. They can't certify a sequence as random or pseudorandom with certainty, but poorly designed pseudorandom number generators will do poorly on these tests. On the other hand, if a sequence does well on these tests then it will be more or less impossible (without knowing the source of the numbers) to tell if it came from a pseudorandom number generator or a genuinely random source. The entire point of 50+ years of research is to ensure that the answer to your question is effectively "No - you can't tell".
To add to the well written answer of John, I would like to add a few remarks.
First, I do believe that out of every "Random Generator", as you name them, none of the random number that you'll get are truly random. Even further, we do not know a way to procude a true "random" sequence of number. The only true random that you can obtain comes from quantic particles as they are not determinist and can be considered at some extent as random. When you have a website or a program that gives you a random number, it comes from a determinist method, which could theoretically be deduced, if we knew all of the initial conditions. Some of the more "random" algorithms, for example, use the variation of the atmosthere as a way to produce a seemingly random result (see this random generator for example). And yet, if we could get all of the parameters used on an instant T, you could theoretically "guess a random number".
What you can do though, if you do not recognise a pattern in your data, is to do a statistical analysis of your data. As John said, there are numerous methods to recognise a correlation between your random values, and you could get some informations about your data. You could use tools on many mathematical programming tools (Matlab, Maple for example ...) to try to analyse your data. But, in the end, you might never be able to tell with a full certainty the veracity of your results.
So, just like John said, NO, you can't.
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.
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.
I hope it's not too obvious a question: is there a random number generation algorithm that doesn't depend on previously returned values, so that I can get (for example) the 50th number in the sequence, without computing the previous 49?
The reason is that I am making roguelike that will be persistent (so that I can recreate the exact same level from the same seed), but to compute certain features of each level, I don't want to have to "compute" all previous features just to get the random number generator to the correct "state" of having been used, for example, 100 times so far. I would like to be able to query the 101st random number without determining previous values so that the program can create level features separately.
You can encrypt ordinary sequence number [1..N] with any cipher,
and by this way - generate unique pseudorandom value for each SeqNo.
If you use a linear congruential random number generator, it is trivial to compute the $n$-th element generated from a given seed. But it is probably easier just to stash away the state at the "interesting" points of the game.
OTOH, if you want to "restart" the game at a certain point, you'll presumably want to be able to recreate the dungeon's features, but (due to different player actions) the RNG usage will be different from then on. I.e., if started at the same point, if I shoot twice at a monster the RNG will be used more times than if I just run away; the next item generated will get different values. Perhaps what you really want is several independent random number streams, and saving the states as needed?
There are lots of roguelike games around, mostly open source. Some are limited/small (from "build a game in a day" sort of competitions), and might make a good starting point for you. Why start your own, and not hack on an existing one?