guypb
06-06-2008, 06:44 AM
Don't ask why - but is there any G/M code (standard or macro) that will create a random number within a range that can be written to a macro variable?
This applies to both Mills & Lathes - but specifically Haas?
cheers!
Interesting question, why are we not allowed to ask why?
I had the same question for a project that did not go anywhere. I never did write anything but I figured it should be possible to write a macro for a pseudo random number generator. I cannot recall the exact details but I think it is a case of taking successive square roots of a large prime number and truncating each result to the number of digits you need for the random numbers.
My application was based on an idea for doing large brushed stainless steel or aluminum panels by having an abrasive disc wander around them randomly on a large gantry router. If the same original prime number is used in the generator it generates the same sequence of random numbers so the pattern would be random on any one sheet but identical between sheets.
neilw20
06-06-2008, 01:29 PM
I start a counter going at high speed looping through zero to a limit.
When you hit a key/button some time later, stop the counter and grab the number. Modified touch tool code with a counter loop would work.
080606-1952 EST USA
neil:
That is the basis of a true random number generator that I invented circa 1953 for use by Wilson P. Tanner in his human signal detectability experiments. Ted Birdsall named the machine N. P. Psytar for Noise Programmed Psychophysical Tester and Recorder. A photograph of this equipment is at
http://www.beta-aa.com/misc_photos.html photo p21.
Also see some more discuussion on N. P. Psytar and my discussion about Pearl Harbor at
http://www.beta-aa.com/misc_info.html
Look for the paragraph starting with "The words "a priori" and "a posteriori" ".
.
Andre' B
06-10-2008, 07:24 AM
Here is a sub and a demo main program, the sub I have used in a program that creates art type pictures. It is not perfectly random but it is simple and good enough for most stuff.
Not going to say a lot about the program since I still think I can make some money with it. ;)
As a teaser I will say it also uses a way of doing reentrant sub calls to about 40 levels deep.
Ok it makes fractal pictures.
If you run this on NCPlot turn off the drawing of the G0 moves.
O1000
#101=1(SEED FOR RAND)
#102=0(RAND RETURN -1 TO 1)
#1=2000(NUMBER OF POINTS)
G0X0Y0
G1X20.0
G1Y20.0
G1X0
G1Y0
WHILE[#1 GT 0]DO1
M98P9900
#24=[#102*10.0+10.0](X POSITION)
M98P9900
#25=[#102*10.0+10.0](Y POSITION)
G0 X[#24-0.1]Y[#25-0.1]
G1 X[#24+0.1]Y[#25+0.1]F10.0
G0 X[#24+0.1]Y[#25-0.1]
G1 X[#24-0.1]Y[#25+0.1]
#1=#1-1
END1
O9900(RAND)
#101=106*#101+1283
#101=#101-6075*FIX[#101/6075]
#102=[[#101/3037]-1.0]
M99
guypb
06-11-2008, 11:41 AM
Hi Andre - looks great!
I'm don't understand why you have #102=0 at the beginning of the O1000 program, as this gets overwritten in the O9900 or is part of the sub missing.
Generating #24 & #25 values is perfect, as I am trying to mimic the variation of a probe on a simulator, so I want values that are randomly within 110% of the tolerance limit of a nominal.
Not quite sure what the relevance of some of the numbers are in your sub, but I'm sure it works and will tell me the number I first though of or my shoe size or something.
When I have access to a control I will give it a try.
Andre' B
06-11-2008, 12:36 PM
Hi Andre - looks great!
I'm don't understand why you have #102=0 at the beginning of the O1000 program, as this gets overwritten in the O9900 or is part of the sub missing.
Just a habit of making sure any global vars. are set to some known value.
Also I like to make a list of global variables used within the program and put it at the top with comments so I can find out what it is intended to do. And if I need to add a variable to a program I just use one that is not in the list therefore not step on some other part of the program. That type of thing tends to happen on the shop floor at the control where the text editor and search is not the easiest to use, and things are often a bit tense.
Generating #24 & #25 values is perfect, as I am trying to mimic the variation of a probe on a simulator, so I want values that are randomly within 110% of the tolerance limit of a nominal.
Like many random number generator functions you just need to you just need to multiply or divide and add on offsets to get numbers in the range you want.
Not quite sure what the relevance of some of the numbers are in your sub, but I'm sure it works and will tell me the number I first though of or my shoe size or something.
When I have access to a control I will give it a try.
So far I have only run it on back plotter software and not on a real mill.
Got the idea from some web page like this.
http://en.wikipedia.org/wiki/Random_number_generator