You don't need to be an 'investor' to invest in Singletrack: 6 days left: 95% of target - Find out more
Number generator...
I need* to generate three columns of numbers which can contain 0 to 255. The columns are important so 0,0,255 is not the same as 0,255,0 or 255,0,0
I need to generate all combinations that are close say within +- of the middle value.
Any ideas?
* Need is strong word, but it is an interesting puzzle.
Edited because I was talking bollocks 🙂
I typed the following prompt into ChatGPT, it spat out some text which I saved & then imported into Excel as a CSV:
"generate a 20 row, 3 column CSV file. The second column should be a random number between 0 and 255. the first and third columns should also be random numbers but each value should not be different by more than 10 from the value of the second column on the same row."
is that what you want? Must admit not really sure how to interpret this:
I need to generate all combinations that are close say within +- of the middle value.
Use RandBetween function? Middle Column (B) would be between 0 and 255. First and Last col (A and C) would be between B-tolerance and b + tolerance.
So if your tolerance was say 20... and the middle random value came out at 100, Col A and Col C would be RandBetween 80 and 120.
is that what you want? Must admit not really sure how to interpret this:
I need to generate all combinations that are close say within +- of the middle value.
Yeah that's fair. +-10 of the middle value not middle column.
As in 8 from 8,6,250
Use RandBetween function? Middle Column (B) would be between 0 and 255. First and Last col (A and C) would be between B-tolerance and b + tolerance.
So if your tolerance was say 20… and the middle random value came out at 100, Col A and Col C would be RandBetween 80 and 120.
It can't be random it needs to be the complete list of combinations. 255is the max value in any cell.
There are 266^3 combinations.....
Best part of 19 million
There are 266^3 combinations…..
Best part of 19 million
There aren't though.
Because most combinations would pass the condition.
Eh
1,11->255,0->255 all pass (or fail, depending on how you look at it)
josh:
this is by no means optimised but is hopefully fairly readable python code:
[code]
limit = 10 ## CHANGE THIS VALUE
all_values = []
output_values = []
for a in range(255):
....for b in range (255):
........for c in range (255):
............all_values.append((a,b,c))
for value in all_values:
....if abs(value[0]-value[1])<=limit and abs(value[2]-value[1])<=limit:
........output_values.append(value)
print(output_values)
[/code]
You may want to import the CSV module and save the output to csv to make it easier to play with.
AHHHHH - annoyingly the code tags on this site don't respect spaces! So i had to put . in - swap all the leading dots for spaces
Cheers poly, I though python would be the answer.
Anyone want to guess what I am doing?
I hope you are not trying to look for similar colours! If you were then probably switching from RGB to a different colour space like HSV would be better!
If its not a one-off you probably want to optimise that so you only generate the number if its in the desired range rather than generate them all and filtering out. I don't know how much python you've done...
C#, loops, and write to CSV. Not too onerous at all.
I hope you are not trying to look for similar colours! If you were then probably switching from RGB to a different colour space like HSV would be better!
I am as it goes, trying to make a background map in some typically shonky utilities maps disappear in QGIS. I don't need to process them just make it easier to see through them. To be honest the 255 identical bands does remove most stuff this is more thought excercise and a reminder I need python skills beyond print("hello world") despite doing fancy edge detection stuff for my dissertation I've never got beyond stealing bits of code and piecing them together.
So anything from white to black and anything greyish.
If its not a one-off you probably want to optimise that so you only generate the number if its in the desired range rather than generate them all and filtering out. I don’t know how much python you’ve done…
Sounds like a first challenge.
I’ve never got beyond stealing bits of code and piecing them together.
Are you ALL the devs in my team?
OK, this was my attempt in a generic mish-mash of languages:
for (middle = 0 ; middle <= 255 ; middle++) {
_ for (first = max(0, middle - 10) ; first <= min (middle + 10, 255) ; first++) {
_ _ for (last = max(0, middle - 10) ; last <= min (middle + 10, 255) ; last++) {
_ _ _ print first . ", " . middle . ", " . last . "\r\n";
_ _ }
_ }
}
Then I re-read the question and realised I don't understand something...
Yeah that’s fair. +-10 of the middle value not middle column.
As in 8 from 8,6,250
Within 10 what? 250 isn't within 10 of 8, so what exactly needs to run from -2 (or presumably 0) to 18 in that case?
Within 10 what? 250 isn’t within 10 of 8, so what exactly needs to run from -2 (or presumably 0) to 18 in that case?
Exactly 250 being out of the range 0 to 18 means it's okay that combination can be ignored.
RGB colouring white proper grey and black are matched values.
0,0,0 is black
X,y,z is some value of grey shade if X=y=z
255,255,255 is white
But greyish colours are almost matched.
So I want a list that checks
That checks or builds a list that satisfies these criteria
X=y+-10 AND X=z+-10
Y=X+-10 AND Y=z+-10
Z=X+-10 AND X=y+-10
If they are satisfied they are "almost grey"
OK, I think I get it, so assuming I've read that right and 10, 20, 30 "passes", I think this should do the job...
for (x = 0 ; x <= 255 ; x++) {
_ for (y = max(0, x - 20); y <= min (255, x + 20) ; y++) {
_ _ for (z = max(0, x - 10, y - 10) ; z <= min(255, x + 10, y + 10) ; z++) {
_ _ _ print x . ", " . y . ", " . z . "\r\n";
_ _ }
_ }
}
Can you not just turn the map layer off 🤷.
Can you not just turn the map layer off 🤷.
I'd love it if this was the answer! (but I'm sure its more complicated than that)

Can you not just turn the map layer off
It's not a map layer it's a georeferenced pdf.
If I turn it off I can't see anything. Honestly the utilities records in the UK are a disgrace. Incomplete disjointed and basically a cluster of ****ery