DL 05 Random Number Generator

Join Date
Aug 2007
Location
louisiana
Posts
3
Can anyone help me create a few ladder logic lines to randomly generate intergers btw 0-100. I have tryed loading the scan timer value, then ANDD, then LD into a memory local (this just seems to toggle btw 2 values). Honestly i am not a programmer; what i have tryed will not work. I understand "completely random" isnt possible and that is totally ok for my app. If you are unsure of the functions i have to work with (it is only the basics) you can download the trial software at www.automationdirect.com. Any help i will greatly thankful for....im an M.E. wish i was a programmer !!!
 
I don't know AD, but in the past i have used a free running timer to generate a random number.

Set up a timer to run repeatedly from 0-100 milliseconds if possible, or hundredths of a second.

When an input (start pushbutton for example) goes true, look at the value in the timer...

If you need to generate a random number every scan or multiple numbers at once, you may want to create an array of one hundred values, and fill it with random numbers dervied externally...then just increment a pointer (indirect address?) to the array when you need a different random number.
 
OkiePC said:
Set up a timer to run repeatedly from 0-100 milliseconds if possible, or hundredths of a second.

.

If you want to use Paul's suggestion... try this

and this would be Micheal's "when condition is true"

Just change C11 to your input or condition and V1200 will hold your number
random11.jpg
 
Dirtysouthdesign,

If you use geniusintraining's code be careful that C11 stays on for only one scan. Otherwise incrementing numbers will appear in v1200 and they will increment by the scan time.
 
Try this code for a pseudo random code in V2000. Energizing C10 grabs a somewhat random number into V2001. Keeping the remainder after a DIVB of K64 (100 decimal) gives you 0-99. You can use 'BCD' after the POP if you need that form. It's actually generating a 16 bit pseudo random number. We're just grabbing a part of it. It's a shift register with XOR feedback. Google it.

PLC 05

// Rung 1
// Address 0
STR SP0
LD K0
OUT V2000

// Rung 2
// Address 3
STR B2000.1
ANDN B2000.2
STRN B2000.1
AND B2000.2
ORSTR
OUT C0

// Rung 3
// Address 13
STR C0
ANDN B2000.4
STRN C0
AND B2000.4
ORSTR
OUT C1

// Rung 4
// Address 21
STR C1
ANDN B2000.15
STRN C1
AND B2000.15
ORSTR
OUT C2

// Rung 5
// Address 29
STR SP1
LD V2000
MULB K2
OUT V2000

// Rung 6
// Address 33
STR C2
SET B2000.0

// Rung 7
// Address 36
STR C10
LD V2000
DIVB K64
POP
OUT V2001

// Rung 8
// Address 41
END

// Rung 9
// Address 42
NOP


#BEGIN ELEMENT_DOC
"C10","Get Rand Numb","",""

#END
 
Thanks guys, i will give this a try tonight. The situation is this. I have 4 linear solenoids that i need firing randomly in time, sequence and with multiple combinations of firings simultaneously. If i can randomly generate numbers say 1-100 or such, then i can implement test rungs for all the combinations, as well as delays before the next scan. Thus creating my semi random multi solenoid firings. think !?
From whats been posted i think i can make this work, i might need a few budweisers and / or tylenol. in this process, thanks again guys. I may post a screen shot of my work if i get stuck.
 
bernie_carlton said:
Try this code [.....] #END

Show off ;)


--------------------------------------------------------------
OT

Bernie, can you edit the program with that view? (the Mnemonic view)
 
No - you can't edit in mnemonic view. That would let you make some constructs which aren't legal. So only the ladder view lets you edit.

The export makes it nice for posts like this since the text can be cut and pasted into a text file then imported. It makes for easy program transfer since it's just text pasted onto the post. Of course a long program would be a bit tedious to view.

Way back (about 1983) I was challenged to do a random number generator in a 5TI sequencer to be a Christmas light random blinker. It worked great.
 
Random number generators are used extensively for controlling solenoids and water features in swimming pools. That is where I use them. They are used for randomly changing timing values usually so that the timing sequence of water spouts etc is in a random pattern.

I also use them to vary the "shift" input into a shift register. Commonly used for varying the pattern and timing of water spouts.

Both systems work - just depends on what the client wants as to how I implement the logic.
 
So i put Berine's code in last night, (No Copy/Paste, the only way to learn is to do) but it works too good. What is the easiest way to slow it down ?? I only need the value in V2001 (Random Value) to change about every second or so, that should be fast enough. I changed the Divisor to reduce the probabiltiy but on a occasion the code still produces the "firing rung" true in 2 sequental scans which is too fast. My solenoid is on a 20ms offdtmr and i need it like that so the mag field builds has time to build up and give a good pop !! I get the feeling some of you guy could fix this in one rung or so. (it would take me ten). Keep in mind the software im using has NO ondtmr, just offdtmr. Thanks again guys/girls.
 
I intended the C10 to be generated whenever you need a new random value. Be sure it's from a one shot situation.

I haven't had an evaluation of "too good" for code before (breaking arm patting self on the back, hatband breaking from swelled head).
 

Similar Topics

Hey folks, I was just wondering what thoughts were about a completely 100% random number generator. I looked on The Google but didn't really open...
Replies
54
Views
16,502
Hello, Could somebody please help me out with coding a 'Random number generator' in vijeo citect. For example if i create an analog Local...
Replies
3
Views
3,749
Hi,Does anybody know if there are any routines in unity pro that produce random numbers like the routine rand() in C ?
Replies
1
Views
4,029
Ive got a client that needs random numbers generated for a security system. Just want to know if any 1 has some ladder or ST software or scripts...
Replies
11
Views
8,852
Hi guys, I need your valuable suggestions about writing a module (AWL Step7) generating random integer numbers... Let's say the users define the...
Replies
19
Views
20,263
Back
Top Bottom