PDA

View Full Version : Creating truly random Randomizers!



Treas
09-28-2009, 12:15 PM
Here's quite an in-depth tutorial on how to create randomzers I wrote a while ago. I thought some of you might find it useful, as quite a few people asked me how I randomized my survival challenges. So, here's the guide:

Most randomizers out there aren't really random, in fact! I call them "pickers" - they pick one of a set of possibilities at any given time. When you let them pick magnetic keys at a set pattern, however (and every pattern is set, even if you add 4 pistons with different speeds or the like), the sequence of magnetic keys may be a random one, but it will be THE SAME whenever you replay your level (and start the pickers at the same moment as before).

Therefore, one must conclude that pickers create one random switch activation pattern, which will then be fix, thus not being random in a sense of being different each time you start it up.

Note: The physics engine of LBP doesn't work 100% accurate. This means that even the not-really-random randomizers might in fact deliver different results from time to time. But, for the sake of doing it right (and saving thermo space, as my method is quite thermo-friendly), let's explain how to create a real randomizer:

I ended up contrifing one saying: "The most random element of each level is the player". Therefore, randomness must, directly or indirectly, be achieved through tracking a player's movement. Now my main method, which comes to use in most of my survival challenges (H 4 Heartbreak, S 4 Stylebreak, SackCrush 3000, Sacksquash, Jungle Drums, Bubble Caves (http://www.lbpcentral.com/forums/showthread.php?t=17010)) is what I call the "Random Heart".

This little machine consists of a thin square of dark matter, 3 circles of cardboard, a magnetic key and any amount of magnetic switches.

Here's how to build it (to simplify things, I added fix sizes. Of course, you can always change the size if you want or need to. The unit used in the description is "MGS", which does not mean metal gear solid, mut "medium grid squares".)

First, place a square of Dark matter (backmost thin layer) with a size of 14x14 MGS.

Next, place a circle of cardboard (backmost thick layer) of 12x12 MGS, centered on the dark matter square. Connect the two using a motorbolt.Let it turn clockwise at a speed of 10.

Next step, place another circle of cardboard (thin layer on top of the first cardboard circle) of 6x6 MGS. The top point of it has to overlap the top point of the greater circle, the lowest point of it must touch the motor bolt of it. In other words: Center it on the top half of the first cardboard circle. Then, connect the two circles using a motor bolt centered on the new circle. Set the speed to 8 and let it turn counter-clockwise.

Next, place another cardboard circle (middle thick layer) of 3x3 MGS centered in the top half of the last circle. Add another motorbolt, speed 6, clockwise.

You should now have a piece of dark matter and 3 circles on top of it, one attached to each other, spinning 'round like crazy.

Ok, so what we gonna do now? Add a magnetic key to the top point of the smallest circle. Depending on how fast each motorbolt turns, this key can now move freely around the whole dark matter area (or at least within the 12x12 MGS of the first circle)

Next step: Attach magnetic switches to the dark matter, wherever you want. I prefer placing them in the corners, without any particular reason. Set the radius so that they cover the whole area where the magnetic key can move. Set them to speed. I recommend adding one magnetic switch for each differend "picker" you've got for your level.

Here comes the magic: Place 3 proximity sensors at random places in your level. Set the radius of each sensor so that all cover the whole playing area of your challenge. Set them to speed and connect each to one of the 3 motor bolts of your "Random Heart". Now, depending on where the player(s) stand at any given moment in the challenge, the speed of the motorbolts will change, the magnetic key will follow another path, and the speed of all pickers will be changed every single second, granting total randomness.

Well, if you could get a player to move EXACTLY, and i really mean exactly, like he did in the last round, then it would'nt be random anymore. But I guess there's noone out there who could achieve such precise movement.

Well, here it is. My great secret to total randomness, now enjoyable by every interested user. I hope though, that this little tutorial might bring you guys away from "BOMB SURVIVAL #39048 OMFG!!!", and deliver us some delicious and original survival challenges!

- Treas.

Rogar
09-28-2009, 03:18 PM
Very clever! I thought of using the player position as a randomizing factor, but I didn't think of controlling speed. A minor flaw: if you stay in the same spot, the pattern will repeat every so often. But that's nitpicking. :p

I'm also wandering about the placement of the magnetic switches. My maths is extremely rusty, but it should be possible to calculate the chances of the key passing any particular point on the dark matter sheet, to see if it matters where you put your switches. Anyone? :D

Treas
09-28-2009, 08:50 PM
Wow, quite a difficult task there!
Well, calculating the exact probability or time/timeframe for a mag switch to pass a certain place on the board for player position X at randomizer starting position Y (which consists of the angle of 3 different motorbolts) would really be quite difficult to calculate.

What you can do is placing the player in a certain spot and leaving him there, observing the randomizer pattern, sketching it down and THEN calculating those values. But this wouldn't serve any purpose, since sleeping players are dead players in a good SC.

To put it simple: At least for my randomizer, there's no accurate way of determinating how probable it is for point A of the moving object to pass fix point B, since multiple immeasurable values serve as an input, time elapsed being one of them.

To get exact random outputs (like, you want something to happen 3 out of 7 times), connect the randomizer to a picker with 7 slots, 4 of them being FALSE, 3 of them TRUE.

rtm223
09-28-2009, 09:00 PM
Nice trick. It kind of assumes that you only need the randomiser in one area of the level. Not exactly but sort of. I made one that had 6 outputs, was seeded by a single event, and would give almost even distribution over the 6 outputs, with no repetition of pattern, even with a periodic sampler. I was quite chuffed, although certainly not so low on the thermo as yours. I'll have to gove this a punt at some point.

Treas
09-28-2009, 10:49 PM
Nice! Well, you could either spread multiple mag switches over the dark matter part of the randomizer or copy and paste it to different locations. But you're right, as it stands, it's more of a local contraption.

The reason is that I'm mostly known for my survival challenges. I tend to create simple, one-screen survivals with lots of random events. That's why I came up with sort of a local solution. Yours sounds pretty interesting too.

By the way, was it you, rtm223, who created a picker (or randomizer) that does never pick 0 or 2 outputs at once? While I've managed to minimize such erratic picks to a minimum, it still happens from time to time. Would be glad if I could take a look at this contraption (not sure whether you were the one who made it, but I thought I'd ask you, just in case).

rtm223
09-29-2009, 12:22 AM
Actually, it was comphermc who got the no two outputs at once down by emitting dissolve into a placeholder with one of several mag keys on it. I took that and made it significantly more random.

In the end the device was a collab really, and it's slightly misleading for me to say I made it. I just made it more random :p


All you do is emit self-dissolving pieces of dissolve into a hole. When you want a new output, trigger the dissolve and either, the next active output, or one of the active outputs will fill the hole. If you make sure at least one is always trying to emit, you will get instant output again. Hopefully this makes sense :)

comphermc
09-29-2009, 12:27 AM
Yeah, it was a group effort! :) No, but it's pretty solid, and fairly low thermo.

Treas
09-29-2009, 08:07 AM
Ah, nice approach! Making sure there's always >0 outputs and then cutting all unnecessary outputs away, I see. Gotta experiment with this idea.

Oh my, the new Survival I'm currently working on will need a whole new dimension of randomizing! There's 2 variable values which will determine which outputs are possible for the next picking process and which not. Gonna make some sort of XY-coordinate-thing (or a series of ANDs to make it simpler and more reliable) to solve that problem. Will still be quite a challenge :)

rtm223
09-29-2009, 11:55 AM
I can think of about 4 or 5 methods for doing a co-ordinate randomiser. A simple bank of n-by-m 2-input AND gates is the easiest but by far the most inefficient. It would also have the quickest response time though. It depends what the requirements of the system are.

Rogar
09-29-2009, 12:12 PM
Hmm, I've given this probability calculation a bit more thought. I think because of symmetry we can assume all points with equal distance from the center to have an equal probability. Furthermore, those rotating circles add or subtract from the radius of the circle they're on. It seems similar to throwing three dice and adding the results, so I wouldn't be surprised if it turns out that the farther out you put the switch, the less likely it is to occur. And maybe closer to the center is also a bit less likely.

I hate probability math. :p

comphermc
09-29-2009, 12:16 PM
I think you're forgetting one small thing. There isn't a linear distribution for the distance from the switch to the key when involving rotating circles. I really can't be bothered to figure it out now, but they will follow a trigonometric distribution. Think of the having a large turntable in front of you. The distance from you to a single point along the turntable will not vary linearly with time, as the table turns. The speed of the object moving away from and towards you will by cyclic and a combination of sines and cosines squared (taking the squareroot of their sum of course :p). Then, you have to factor in the triple rotating circles and find a nice reference point for your calculation.

Sorry for the digression.

rtm223
09-29-2009, 12:26 PM
It doesn't matter.

The position of the mag key does not give the random outputs, it gives variable speeds (taps) to pickers , if I understand correctly. Now the speed of the picker will not have a uniform distribution, but by placing all of the keys around the heart, each picker will be equivalent in it's speed distribution. The actual rate at which each one picks will be largely independent of each other and so the overall randomisation would be achieved.

Right?

Personally I would do away with the pickers and just have N mag switches at the center of the circle, facing outwards, with slightly overlapping angles and then feed that into the max on at a time selector.

In fact I could just wire speed proxes in to the tapping pistons in my design, right comphy? That would add to it wouldn't it?

comphermc
09-29-2009, 12:50 PM
In fact I could just wire speed proxes in to the tapping pistons in my design, right comphy? That would add to it wouldn't it?

Don't see why not... It might add to it a bit.

Treas
09-29-2009, 01:55 PM
This thread gets quite interesting!

You're absolutely correct, rtm. The random heart does not give any outputs into the level; it's just kind of a meta-object, taking the player positioning (and/or other random values that can be used for this purpose) to create a constantly (and, most important, randomly) changing "speed" value for the actual picking device.

Of course, a brute-force AND-chain would be the most inefficient system, and a coordinate-based solution would make more sense. One advantage of AND-chains is that you could link up 3 values (while coordinates are restricted to XY because they're stuck in one layer). And, as you pointed out correctly, AND-chains have got better reaction time while being stable and reliable.

Another problem you'd have to solve when using a grid is that the key block might activate other mag switches on its way from A to B. Any solution I could think of would cost some additional thermo space.

That's why I stick to my AND-chain.

rtm223
09-29-2009, 03:08 PM
Think about this (assuming n is the total number of positions on your shorter axis of your grid, and the shorter axis is denoted X.):

Select an X-coordinate position. Emit dark matter blocker. (0.1s)

Move a piston to this position (n / 10s) - i.e move one step per 0.1s.

Select a Y axis position and emit a key into the correct spot (0.1s) - this be detected and can trigger an event at the co-ordinates. This can be optimised if all positions emit the same object.

Bring the piston back to starting point using a winch (0.1s).

Pause (0.1s)

Repeat. You can trigger an event at a random position in 2d, every [ (x/10)+0.4 ] seconds. Not that fast, but quite fast

Unless you have a big grid, or you need very fast spawning, this would be a very thermofriendly way to achieve it. You can even incorporate the "only one output valid at a time" into both of the X and Y pickers. Plus, it's far more fun than wiring up m x n AND gates and it would look cool to watch it moving about. Plus extensibility and easier to debug. No 3d though.

I will probably build this at some point for a tech demo...

Treas
09-29-2009, 03:19 PM
I agree, this would definitely be quite thermo-friendly if done right (which is what you are clearly capable of) and fun to watch. At the same time, a good, elaborate AND-system is also quite easy to debug and as fast as it can possibly be (well, 0.1 seconds. Emitter-gates work faster, but they're better for OneShot-mechanisms than for directional values).

By the way, I've got an interesting question:

What's the speed of emitting?
Simple experiment: One emitter emitting a DM-block (lifespan 0.1) with a key next to a switch. Switch set to OneShot.

Copy and paste this device and connect each switch to the emitter of the next block.

I've tried this with about 30 emitters and the reaction time seemed to be 0. Regarding the fact that each emit-detect-activate-step would take quite a few processing steps, however, I ended up thinking that it must take some time to forward this signal. Wasn't at my ps3 at that time tough, so I couldn't test it out.

Any guesses or experiments? If not, I'm gonna try this out myself tonight.

UPDATE:

Quite an interesting outcome. I've linked up approximately 300 emitter-linkers to build a chain (emit, activate switch, let the switch activate emitter, emit, activate next switch etc.). There's NO delay between activating the first switch and getting the feedback from the last part of the chain. However, such long chains lead to a sudden freeze (duration of the freeze depending on the chain length/ complexity of the operation performed. It was about 0.5s for me).

Rogar
09-29-2009, 03:51 PM
I'm not sure I understand the goals of the x-y randomizer, but couldn't you just use a speedy version of the original post to drive two flipper pistons randomly across the probability space and then have a kind of sampler mechanism select a random position at regular intervals?

deboerdave
09-29-2009, 03:57 PM
interesting idea having the player involved with the speed switch. Does your system have controll over the distribution of events. Meaning can force it to draw from a uniform distribution or a skewed or a symetrical distribution. Example you have three outputs A B and C. Uniform A B and C are equally likely to happen, Skewed (example) A twice as likely as B and four times likey then C., symetric (example) A twice as likely as B and also twice as likely as C.

I have played with making a randomizer. As i wanted to have a pair of dice, So i was concerend that each die was independent of each other and that within a single die consecutive rolls are not correlated no matter the speed of rerolling. I also of course wanted uniform probability of choosing 1 through 6 on each die. i am not sure how thermo heavy my design is but i like it, and believe it has met all my critera.

As for the issue of picking 0 or 2outputs at once, i was originaly using mag switches for picking and noticed i would get zero out puts sometimes (two outputs was impossible with my design). I simply solved this by changing to paint switches, a paint ball can only land on one surface and it can not miss the surfaces (unless your emit design is poor).

i ask about controling the distribution becuase i also had the idea of creating a randomizer that mimiced the distribution of the sum of the two dice, which would a symetric distribution about 7. I can get this distribution by simple adding on to my two independent die and actualy going through an adding process, but i can also modify my original design so that original selector has the distribution that is desired.

rtm223
09-29-2009, 06:22 PM
@Treas: That result is very reassuring to me. I was wondering if there would be a cut-off point on the 0-time propogation of 1-shots, but it seems there isn't. Hopefully this is true for everything else - synchronisation is more important than framerate -> reliability in our designs. My contraption challenge entry relies on a variety of timing contstraints and will literally explode if they are not accurate. I was mildly worried about laggy conditions, but you have certainly reassured me.

@rogar: how would you randomly drive flippers? There sia fair more complexity that would have to be added to the design as well and 2D flippers would probably be messy due to the bendiness of pistons in series. IDK but my gut says that design would end up being very complex once you added the supporting logic necessary.

@dave: The paintball idea is pretty cool. Comphermc and I were looking for a truely generic randomiser though, and it would be a pain to hold one output high until the next is ready to go (one of the tihngs we were looking for for genericism - that's a word right?). That feature is rarely though (and TBH I don't think we even considered paintballs :p)

I could create a arbitrary distribution with my design, as the outputs end up being mag switches even spread around a circle... Just tweak the angles / radii and positioning. I'm not sure how accurate you could get it, but for the purposes of LBP I think it would be adequate.

deboerdave
09-29-2009, 07:51 PM
@dave: The paintball idea is pretty cool. Comphermc and I were looking for a truely generic randomiser though, and it would be a pain to hold one output high until the next is ready to go (one of the tihngs we were looking for for genericism - that's a word right?). That feature is rarely though (and TBH I don't think we even considered paintballs :p)

I could create a arbitrary distribution with my design, as the outputs end up being mag switches even spread around a circle... Just tweak the angles / radii and positioning. I'm not sure how accurate you could get it, but for the purposes of LBP I think it would be adequate.

I am not sure what you ment by genericism, but if you are using a circle for your outputs i see no reason you cant use paint switches. that is similar to my main component, I actual feel i have more acuracy with the paint switch then when i had magnetic switches, as i took hexigons and used the corner edit tool and made the hexigon to have six seperate edges (by deleting the extra vertices down to a triangle, then starting over to make the next edge). This resulted in a perfect hexagon with six equal edges and the edges lay flush against each other. These are attach to the circle that rotates them. a paint ball is emmited and can only activate one of the six edges and there is no way it can miss or hit two. Working with the geometry rather than the angles of the magswitch and manual placement of the mag switch i can get a higher accuracy of distribution on my system.

that is the main component i am using for my dice, but it gets more complicated then just using one rotating item, if you ever want to check it out i can show you

Treas
09-29-2009, 09:15 PM
@deboerdave:

Thanks! Adding paintswitches is brillant. Just brillant. Didn't even think of those. Such a paint contraption will be slightly less thermo-friendly due to the "perfect circle" with 0 vertices being split up in a certain amount (8 in my case) of triangles, but considering the fact that 10 was the largest amount of random pickers used in a level, this shouldn't really matter.

I'll work with your paint switch idea! Thanks!

@rtm:

Same for me. Having a desync would be horrible. Instead, it still all happens in one single frame, it just drops the framerate until all operations are resolved. I'm glad it works this way.

comphermc
09-30-2009, 02:58 AM
Hey rtm, if we wanted the outputs to be of the one-shot variety, it would be pretty easy to transform ours a bit using paintballs. In fact, it should be possible to work it out so that no output will be repeated, rather deferred to the next possible output. This doesn't make everything statistically equivalent, but in terms of a working randomizer for a survival challenge, it might be nice to have no output repeated.

I was going to go to bed, but my interest is piqued.

Edit: Sadly, I completely lost my train of thought of what I was going to make. Let's hope I can figure it out...

Incinerator22
09-30-2009, 03:36 AM
too... much instruction... brain hurts... But on a separate unrelated note, Sack-Crush 3000 is awesome lol.

comphermc
09-30-2009, 04:01 AM
Well, I failed in all designs. I'm not giving up yet, but I have nothing to show for my work so far.

I had a working model that used no emitters at all, but it was sometimes unreliable (stupid flipper pistons). This would mean that sometimes it would fail to fire one of the outputs.

Rogar
09-30-2009, 09:28 AM
@rogar: how would you randomly drive flippers? There sia fair more complexity that would have to be added to the design as well and 2D flippers would probably be messy due to the bendiness of pistons in series. IDK but my gut says that design would end up being very complex once you added the supporting logic necessary.

Bendiness? That's randomisation, that is! ;)

I had a go yesterday, and indeed I had to give up the flipping motion, because it would break the pistons. But I did end up with a somewhat random movement across the 2D space. Maybe erratically circular would be the correct word. I think my 3 circle stack needs tweaking. :)

rtm223
09-30-2009, 09:37 AM
@conph and doberbave. The point on genericism (it's made up word OK, I'm sorry), is to make a device that could be used for ANY putpose. The paintball version does 1-shot outputs, and that is all. You have to add extra logic to get other output types and if you wanted to make a selection, then keep that output On until the next output at which point it goes off agian, it would be a pain. As I said it's not a feature that's that often required. The version we made could output directional, on/off, one-shot signals happily with no modification.

@comph - we could make our one statistically equivalent AND prevent duplicate outputs if you want. With only a minor tweak to the system. I can't be bothered to explina, but I did something similar where an object is emitted and it's output is disabled. The emitted objects then later actually tell the randomiser when to re-enable the output that produced them.

Killian
09-30-2009, 04:38 PM
Very interesting technique. I remember being impressed by the lack of repetition in your levels, now I see. ;)

springs86
09-30-2009, 04:52 PM
I really could have used this months ago when i was building my eliminator SC, but still, it sounds awesome

srgt_poptart
10-15-2009, 01:47 AM
Im making a kinda original survival challenge, which is going to use a randomizer and player tracking devices. If you wanna check it out, it'll be published on author Freedom_Corn, sometime before the end of November. It's randomizer does not use player tracking, but it is still pretty random. Has 8 possibilities.

MegaRock35
12-05-2009, 12:52 PM
The Random Heart works really well. I'm using it in a survival challenge. Connected the mag keys to emitters that are mounted on moving block for even more randomness.

slutzinc
01-12-2011, 07:24 AM
Just wanted to let you know I've published a lightning generator using your fantastic randomizer. The level is nothing special to look at, but... credit where credit's due, you know?

Askingalexandria
01-17-2011, 08:09 PM
The randomizer great work! it was amazing it was great fun to use I guess. considering i did have some problems it would make me lagg and my friends lagg way to much dont ask why cause I dont know