How to make randomized numbers but if they are too close, change it - libgdx

I want to make randomized numbers but if they are too close, I want to make it a reroll or make it a number further away from the the other number or try to make it a little more spread out.
I guess I am not sure what exactly I want :/
Thanks in advance
EDIT: So the reason i am making randomized numbers is for spawning positions for units on sides of the screen so i want units to not be too close to each other essentially to make it look better.

I want to make randomized numbers but if they are too close, I want to
make it a reroll or make it a number further away from the the other
number or try to make it a little more spread out.
A random number generator sometimes produces numbers that are near each other.
If you don't want them so close together, maybe what you need is fixed numbers each with a small random perturbation.
Let's say you choose numbers 10, 20, 30, 40, and 50. Then, you run a random number generator that gives you a number between -3 and +3. You add this random number to each one in turn. This produces numbers that aren't uniform, but they're not too close to one another.

If a re-roll would be sufficient, you could just save the previous value, and then on the next iteration, if the difference between the two numbers is too small, call Math.rand() again. Maybe your sample space is too small?

Get random position
If it's not good (too close to some other or what ever) go to step 1.
There you go! You got valid position. :)
...
Or...pre-calculate all valid positions, place them in some array and use rnd function to get array indexes - what array elements will use. That should be the faster solution (if you have huge number of units)...

Related

Length of line overlap

I have two lines, I use "ST_LineCrossingDirection" to detect if the two lines cross each other.
If they do cross, how do I check the length of the overlap? Is there a function that returns a metric to indicate the size of their overlap?
For example, lines that do intersect but are perpendicular, length of overlap would be minimum. For lines that intersect, and run on the same route for some distance, the length of the overlap could quanity "overlap distance"
Any tips to get this?
Thanks
ST_Intersection will give you a collection of pieces of the lines that are mutual, if you want a bit more tolerance use ST_Buffer on one of the lines first. Then do a Sum() of the ST_Length of those pieces.
I had to use ST_length(ST_LineFromMultiPoint(ST_Intersection(geom1, geom2))) since intersection was giving me a multipoint geometry object.
Thanks for you help!

How to make a drop down list as wide as its biggest item

I have a drop down (Combo Box) in MS Access that I would like to make as wide as it's biggest item. At the moment it's currently set to the following:
ListWidth 3.5"
ColumnWidths 1.75";1.75"
This is ok for values that are smaller than this but a problem occurs when longer values come in. I googled the question and found a way to dynamically make a drop down bigger here but this seems rather complicated for what I want.
Does any one have any suggestions - like would it require iterating over the source contents, checking each individual value for its length and if its bigger than the biggest to that point - set it as the biggest and move on until the end of the values is reached.
Thanks
First I would do a query with the SQL string
SELECT TOP 1 * FROM Table ORDER BY Len(Field) Desc
Then create a recordset, do a movefirst and finally multiply the length of the string with the size of one character.
Sorry for any fault in my text. English is not my first language.

Rotating in glutIdleFunc within a specified range

Let's say I have this glutIdleFunc going in the background of an OpenGL scene containing a little creature with multiple, radially arranged legs that "pulsate":
void PulsateLegs(void)
{
lowerLegsRot = (lowerLegsRot + 1)%360;
glutPostRedisplay();
}
...where the lowerLegsRot value is used like this in the display function:
glRotatef((GLfloat)lowerLegsRot, 1.0, 0.0, 0.0);
It's hard to visualize without seeing what the little fellow actually looks like, but it's clear that this function is making the legs spin all the way around repeatedly. I want to limit this spin to a certain range (say, -15 to 50 degrees), and, furthermore, to make the legs go back and forth within the range, like a pendulum.
Since I'm going for a 65 degree swath, I tried just changing "%360" to "%65" as a first step. But this made the legs go way too fast, and I cannot use a lower increment value if I want to use modulus, which only works on ints.
Is there another way to achieve the desired first-step behavior? More importantly, how can I make the legs go back and forth? It's kind of hard to conceptualize with a function that is getting called multiple times (vs. just using a loop structure that takes care of everything, which I tried before I realized this!)
and I cannot use a lower increment value if I want to use modulus, which only works on ints.
The % operator is broken anyway. You should not use integers, but floats, and use the fmod (double) or fmodf (float) function.

Need help understanding Conway's Game of Life

I'm trying to write code for Conway's Game of Life to determine the immediate next pattern for a given pattern of cells, but I'm not sure whether I really understand the steps. So for example consider the below toad pattern. The cells marked x are alive and those marked - are dead.
-XXX
XXX-
The above should transpose into the following
--x-
x--x
x--x
-x--
The rules as we know are:
A live cell with less than 2 or more than 3 neighbours dies
A live cell with exactly 2 or 3 neighbours survives
A dead cell with exactly 3 neighbours comes to life.
So, the first cell in the input c[0,0] is - and it has 3 live neigbours (one horizontally,vertically and diagonally each), so it should be alive in the output, but it's not. Can someone please explain?
The middle two rows in your output are the ones that correspond to the two rows in your input. The upper left cell in the input corresponds to the second row extreme left in the output, and as you can see, it's alive.
It is alive in the output. It's right here:
--x-
x--x
x--x
-x--
The x in the first row is above the first row in the first output. The rules of Life assume an unbounded plane. If you want to call the top row of the first output 0, you can, but then the top row of the second output is -1.
Well it is. Your 2-line long input is the middle part of your 4-line output. I think when you look at it now you'll understand everything.
Have you looked at least at wikipedia?

How can I make the column widths of a list box in MS-Access2007 automatically size themselves correctly?

Background info:
I was handed a "Tool", which was made using MS-Access 2007, and asked to add some things... The tool is basically a collection of options for querying a database. On a form titled CreatedReport there is a listbox that is bound to a table called analyzed which has all of resulting data from the query/queries that ran. The original creator of this tool set the column widths to specific values but with the new collection of possible results, those widths are very far off.
Desired Outcome:
The final result I want to achieve is, of course, to have the columns be the correct widths for the info that is in the columns. As long as that is achieved, I really don't care which route I have to take to get there.
Question:
How can I get the columns in a listbox in MS-Access 2007 to be sized appropriately for each use? Is there an auto-size feature I haven't stumbled across yet or do I need to hard code the set of column widths for each group? This wouldn't be too hard to do since there would only be about 4 or 5 different groups but I would prefer for the process to be automatic if at all possible.
Another approach would be to have the results returned in a sub form datasheet view, then the user can adjust the column widths also to set the widths automatically use code like this:
Example
This example takes effect in Datasheet view of the open Customers form. It sets the column to fit the size of the visible text.
Forms![Customers]![Address].ColumnWidth = -2
You could put this code into the Current Event of the sub form.
I don't think that Robert Harvey's answer is actually responsive to your question.
What you need to do is:
calculate the maximum length of the values in each column,
AND
figure out, based on the font in use, how wide the column should be.
Note that you may not actually want to set it to the maximum width if the value exceeds a certain threshold.
I don't know to do the second taks, but I suspect Stephen Lebans has already done the work on it. You might want to search his website for it.
Last time I checked, you still had to write code for this.
Your best bet is to use a resizer someone has already written. Here is a good one. It's old, but it shoul still work:
http://www.jamiessoftware.tk/resizeform/rf_jump.html
This is a quick solution that should help when you want to set up listview columns of different widths, and you know in advance the widths you want (eg, you know that column X will always be a 2-character State abbreviation, and column Y will always be a city name).
Just supply all the widths as a single semi colon-delimited string. Code each width as a number and a unit, such as 'in' or 'cm'. This worked well for me: Me.lsvPayHist.ColumnWidths = "1.0 in;0.8 in;1.0 in;1.0 in;2.0 in"