how to change the likely-hood of something happening?

basicly im wondering how you could change the chances of stuff happening in blender, like a coin flip is a 50/50 chance, but like a dice is 1 in 6 chances that a certain number will face up.
im wondering how i could change these odds.

to go more in depth this is sort of what i want, every 10 logic steps, i want blender to pick a number between 1 and 10, and if it matches 3 then it makes a cube move

thanks

random actuator?

http://dl.dropbox.com/u/8845134/forums/lbrkepl.jpg


from random import randint

if randint(1, 10) == 3:
    moveCube()

Thanks, very clear example for a nooobie.

@monster, i have tried that, but the random actuator isnt…random enough, everytime you start the game it puts out the exacts same sequence of “random” numbers, like the first time i do it it goes “1, 2, 8, 4, 7, 2, 9, 5, 10, 3, 6, 3.” and the next time i start the game engine it does the exact same sequence. i was looking for a way to do “real” random numbers. thanks though

Content has been removed. MayDev

You have to set the seed value, if you leave it at the default = 0, then it is not random! (see here and here)

As an aside, technically speaking, getting a true random number generator is very, very difficult. Even the best algorithms are theoretically cyclical and can be decoded with sufficient computing power. What is worse is that certain results can cause them to become stuck repeating the same pattern over and over again.

There is an interesting discussion in the archives dating from 2002 on the best way to simulate a random number generator in Blender.

By the way, “Liklyhood” and “Probability” are not the same thing and should not be confused, When I saw your post title, “I thought oh my oh my… oh goodness gracious me…”

Suffice to say I was disappointed.

Re-reading the archive I linked to, it is not as interesting as I thought. Though you could use Pythons built in random number generator.

Content has been removed. MayDev

Just as addon to Irvines post.

There are no true random numbers in software. This is just impossible just be the nature of how our computers work.

Instead we have pseudo-random generators. You can find it at wikipedia look for Pseudorandomness.
There are some properties this generators should fullfill ( I can’t find it in Wiki, but I refer to university subjekt stochastic).

  1. They should generate number sequences that beave like random number sequences (this wasn’t the case in some early C implementations)
  2. They should use the full value range (all numbers should be present in the sequence when long enough [this wasn’t the case in some early C implementations])
  3. They should be repeatable (which is very important for simulations)

I think there were more, but I can’t remember.

It is important to know, with the same seed the random actuator returns the same sequence. This is good for simulation, because you can run the same simulation again and again and it still behaves random.

I thought (you can try it) that with seed 0 the seed is replaced with something else (time?)

Tried it in 2.49b. With seed 0 the first generated number is different between two BGE starts/two random actuators.
A good and common way to create a seed is to use the current time. The randomness is when the user started the game. Because that usually can’t be pre-calculated.

I do not know how good the pseudo random generator is, but it should be good enough for a game.

In addition look for Probability_distribution. Here you can find an explaination what the different distributions mean (uniform, Bernoulli etc.).

@MayhemOfHell,

keep in mind pseudo-random numbers generated from the generator are usually present in the full range of the internal implementation. I think integer and/or float.
The numbers should not repeat until you retrieved all numbers. After that the sequence will repeat.

If you enter a range, the internal number is just transformed into your range.
e.g: your random number = min + (internal random / max internal) * (max-min)

If your range is smaller than the value range of the internal implementation you will get repeats, just because of the non-accuracy of the transformation (8.35678 in int = 8, while 8.278345 = 8 as well).

I hope it helps
Monster

Probably not really relevant, but to give you an idea of this subjects complexity:

In theory, you can in fact make “true” random number generators, but you would have to use hardware. The various ideas proposed involve using things like “quantum virtual particles” and “thermal noise”. Suffice to say nobody has ever managed to make a practical demonstration work. This is despite aggregated research budgets reaching into the billions of Euros. This and the related problem of predicting a “pseudo random sequence” are some of the best financed areas in modern computing.

You can use the time of day or mouse position to introduce some extra randomness when you need it.

Content has been removed. MayDev

I swithered about posting this, but it might help some struggling student. The problem with random numbers is not really one of calculation, but more accurately “How long is a piece of string?”

It is a recurrent problem when you try to apply pure maths to the real world, for example “weather forecasts”: The measured “differentials”, (ie calculus,) are in fact several hundred square kilometers in area. So, the forecast for a specific area, like your favourite ski resort, can never be more speciffic than an area several hundred square kilometers around the ski resort.

In the case of pseudo random generators, they appear to be “very random”, (or are indistinguishable from true random,) over a short sequence. But… how long is a short sequence?

Using a modified algorithm to re-seed from the a time, date, keypress, mouse… etc are all in fact predictable and this is why the direction of research is towards using natural phenomena that are by definition truly random and unpredictable.

Content has been removed. MayDev

Good idea, but unfortunately how I move around in front of my web-cam has a natural pattern that can be detected. Especially by people who are motivated by the thought of stealing large amounts of money.:stuck_out_tongue:

Content has been removed. MayDev

Again, they have a predictable cycle: day, night, morning rush hour evening rush hour… etc.

Many years ago, I was doing some research at CERN using some very sensitive magnetic phenomena. I had real problems with magnetic noise from the electricity power lines. One of the most noticable aspects was that the quality of the noise was cyclical. On the grand scale, I could detect large numbers of people coming home from work and switching on the kettle, to a more local level with groups of my colleagues taking coffee breaks in their offices. The same applies to radio, the cyclical nature of radio noise is well documented by astronomers.

Finding true randomness is surprisingly difficult. For example, in cryptography, the only system that is considered to be unbreakable is “one time pads” that are generated by a secretary drawing random balls from a sack. Even then, if the secretary and the spy sending the message do not follow procedures exactly, then the messages can, and have, been broken.

Take “terrorist alerts” these are often based on little more than detecting patterns in international phone calls. So called “Quantum Hedge Funds” specialize in detecting patterns in the “random” movements of stock indexes… This is big money and big science, it is usually very proprietary with the algorithms either closely guarded comercial secrets or even national secrets that have “exucitive orders” allowing the use of the ultimate lethal sanction to protect them.

Content has been removed. MayDev