Your question is somewhat confusing. It seems to me that what you want is to initialize the elements of the array such that the total numbers EACH of sedans, trucks and SUVs is some constant known in advance (algebraically, s+t+u = a*b where a and b are the dimensions of the array and s, t and u are the known-in-advance numbers of sedans, trucks and SUVs respectively), but their positions in the array are random.
Here's how I would do it. First, set up a 1D array (let's call it 'src', short for 'source') with a length of 3 (because you have 3 types of cars), and set each of its elements equal to the number of the associated type of car. For instance, let's say sedans have index 0, trucks have index 1 and SUVs have index 2, and let's say you have a 3x3 array you want to fill randomly. That means the elements in src must all be nonnegative and add to 9. For instance, we could do the following:
src[0]=5;
src[1]=2;
src[2]=2;
which would mean 'five sedans, two trucks and two SUVs'. Now, iterate through the 2D array in a simple, nonrandom fashion. But keep a variable around representing the number of cars remaining to be assigned, let's call it 'rem', short for 'remaining'. For instance, in the above example, we would initialize it to 9, and subtract 1 on completion of every inner loop iteration in the 2D array. For each cell, get a random integer from 1 to rem, then iterate upwards through src subtracting the corresponding value in src from rem until it goes to 0 or less, in which case stop, assign that type of car to that cell, and subtract 1 from the corresponding element in src and from rem.
The following Java code (where rand(int min,int max) is assumed to return a random integer from min to max inclusive; car is the double array passed in to be initialized; src is the externally initialized array fitting the properties described above) implements this logic:
public static void populate(double[][] car,int[] src)
{
int rem=0;
int i=0;
for(;i
{
rem+=src[i];
}
for(int x=0;x
{
for(int y=0;y
{
int p=rand(1,rem);
for(i=0;i
{
p-=src[i];
if(p<=0)
{
break;
}
}
car[x][y]=(double)i;
rem--;
src[i]--;
}
}
}
Implementations for C and C++ would be a little harder, because they don't store array length explicitly, so you would have to pass in a few extra arguments. I haven't actually tested the above code, but at least you can see the principle of what's going on here. Notice how instead of randomly selecting the cell and putting in a deterministic car type, we're randomly selecting the car type and putting it in a deterministic cell. This is faster and achieves the same logical result. You may of course have to adjust the code a bit to conform to whatever model you're fitting this into.