Generating random numbers during program execution...??

All things related to Centroid Oak, Allin1DC, MPU11 and Legacy products

Moderator: cnckeith

Post Reply
doug98105
Posts: 3
Joined: Wed Oct 10, 2018 5:08 am
Acorn CNC Controller: No
Allin1DC CNC Controller: Yes
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC11: Yes
CPU10 or CPU7: No

Generating random numbers during program execution...??

Post by doug98105 »

The Centroid macro language doesn't include a random number function.

Is there a way to generate random numbers during program execution using existing macro functions ? Why???, because I'm doing a project where I want to drill a random pattern of holes with each run of the program giving a different hole pattern.

I can do this in CAD/CAM, but it's cumbersome because of having to create a separate program for each program run. In other words if I want, for instance, 50 random hole pattern parts I'd have to create 50 separate programs.
Last edited by doug98105 on Mon May 22, 2023 10:16 am, edited 1 time in total.


tblough
Community Expert
Posts: 3540
Joined: Tue Mar 22, 2016 10:03 am
Acorn CNC Controller: Yes
Allin1DC CNC Controller: Yes
Oak CNC controller: Yes
CNC Control System Serial Number: 100505
100327
102696
103432
7804732B977B-0624192192
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No
Location: Boston, MA
Contact:

Re: Generating random numbers during program execution...??

Post by tblough »

Based on Wikipedia:

#100 = (1103515245 * #25012 + 12345) % (2^31);

Parameter #25012 is the time in seconds from CNC12 as a seed
Cheers,

Tom
Confidence is the feeling you have before you fully understand the situation.
I have CDO. It's like OCD, but the letters are where they should be.


eng199
Posts: 447
Joined: Fri Jan 10, 2014 11:29 am
Acorn CNC Controller: Yes
Plasma CNC Controller: No
AcornSix CNC Controller: Yes
Allin1DC CNC Controller: Yes
Hickory CNC Controller: Yes
Oak CNC controller: Yes
CNC Control System Serial Number: none
DC3IOB: Yes
CNC12: Yes
CNC11: Yes
CPU10 or CPU7: Yes
Location: Howard, PA

Re: Generating random numbers during program execution...??

Post by eng199 »

The system variables should allow you to put something together. #25011 or #25012 times could work in some cases, or could be a seed for a pseudorandom calculation you can find online.

If your machine has a spindle encoder, it should be a good random number in most cases, if you are machining between calculations. Spindle encoder should be somewhere in #5021 - #5028, depending on mapping.


doug98105
Posts: 3
Joined: Wed Oct 10, 2018 5:08 am
Acorn CNC Controller: No
Allin1DC CNC Controller: Yes
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC11: Yes
CPU10 or CPU7: No

Re: Generating random numbers during program execution...??

Post by doug98105 »

Thanks for the replies. Using #25012 seems to do the trick. I'll do some testing the next few days to verify.

My machine doesn't have a spindle encoder so that method is out.


Post Reply