First,im sorry my bad english.I hope,i can tell my problem.

there is a string: dizi[5]={1,2,3,4,5}

and when program run, i want to change random place of members.i mean;
first time program running:
dizi[5]={2,4,1,3,5}

second time program running:
dizi[5]={5,3,1,2,4}

3th program running:
dizi[5]={4,2,1,3,5}
.
.
.
etc..
always changes random.how i can do it?

Recommended Answers

All 6 Replies

I assume you want to randomize these values on startup? if so, then don't initialize the dizi[5] array on startup, but have an initialization function that will set the values randomly. IE,

void randomizeArray(int array*, int arraySize)
{
    for (int i = 0; i < arraySize; i++)
    {
        array[i] = some_unique_random_value_between_1_and_5;
    }
}
int main(void)
{
    int dizi[5];
    randomizeArray(dizi, 5);
.
.
.
    return 0;
}

void randomizeArray(int array*, int arraySize) //should be *array
just correcting trivial details :)

Actually, should be void randomize (int* array, int arraySize)... :-) Thanks. Keyboard keeps changing what I am typing!

Actually, should be void randomize (int* array, int arraySize)... :-) Thanks. Keyboard keeps changing what I am typing!

void randomize(...), maybe you meant void randomizeArray(...) as to be consistent with the code you posted

Sorry just nitpicking here :)

how?manuel?
i want to otomaticly.
program must choose random in dizi[5].

If you meant that (i.e. the above soln.) then fine...
but somehow i feel that you don't want random elements but you just want to display the same elements randomly (i observe that 1,2,3,4,5 were not changing)

In that case, you can randomize array indexes while displaying the elements.

Ok, enough hints...try to come up with some code with all the ideas you have gathered so far!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.