0
I have the following vector:
[**17, 17**, 1954, 909, **17, 17**, 411, 844, **17, 17**, 1954, 909, **17, 17**, 411, 844]
As noted, the indices [0,1]; [4,5]; [8, 9] and [12, 13] are equal.
I need to assign a random value, but equal, index [8, 9] and [12, 13].
How do I create the necessary logic for this situation? and future situations with larger vectors?
For example, the output vector should look like this:
[17, 17, 1954, 909, 17, 17, 411, 844, **23, 23**, 1954, 909, **23, 23**, 411, 844]
You generate a single random number, store it in the variable
meu_numero_aleatorio_para_usar_adiante
and then do for each indexidx
desired the following:vetor[idx] = meu_numero_aleatorio_para_usar_adiante
. Might even make:for idx in ( 8, 9, 12, 13 ):
and then the code to put the value in the index– Jefferson Quesado
Will they always be in the same indexes even if the vector is larger? If not, how to define in which indexes should the substitution be made? What are the limits to the random number?
– Woss
Your questions are interesting @Andersoncarloswoss and I will try to explain the logic I am trying to create. It is the following: - At each 8 positions I assign, at that position a[i] and at the following a[i+1], a random value from 0 to 100. In the given example, I traversed the vector at these positions and assigned the value 23. - Every 12 positions I assign, at that position a[j] and the following at[j + 1], the same value assigned at positions a[i] and[i +1]. - This logic is repeated until the end of the vector. - I don’t know if I was very clear, but if I need to explain better.
– Danilo
And will always be assigned in the top positions?
– Woss
Exactly @Andersoncarloswoss.
– Danilo
And what have you tried to do? What was the difficulty?
– Woss
@Andersoncarloswoss has already managed to change the values of the positions a[i] and[i + 1], but I cannot make the positions a[j] and[j + 1] equal the values of the positions a[i] and a[i+1]. I can’t post the code right now, because I don’t have it on me right now.
– Danilo
@Andersoncarloswoss has some idea how I can do it?
– Danilo
Then please edit the question by adding all the information you have put here in the comments and the code you have developed. So the question will be clearer and will make it easier to help you.
– Woss
That’s right @Andersoncarloswoss, I’ll do it later (I’m not near the system) (even to help people in the future). Thanks anyway.
– Danilo