### random values between a range

Hello guys,

i have to find 2 random values between a range, lets say from 0-3 i have to find all the possible combinations between this range like (0,0),(0,1)...etc But, it has to be RANDOM and the same combination cannot repeat it self(obviously).

Thank you.
I didn't get you. Please elaborate.
ok i will try a different example, if i have 2 dices in a game which have numbers from 0-3 on each side and i roll the 2 dices, i would like to get all the possible combinations from these dices RANDOMLY.
You do understand that if you trow dices two times the might get you the same value randomly, right? You should also tell if two dices are distinct or same (if combinations (1; 2) and (2; 1) are different). If you want all combination randomly shuffled, you might generate all combinations first and then shuffle it.

BTW. The best way to show what do you want is to give sample input and output with nessesary comments.
thank you for the reply,

what im tryin to make is a small board game with randomly determined x,y locations for the dice , i already have the possible combinations(for 16 dice) they are:
0, 0 dice1
0, 1
0, 2
0, 3
1, 0
1, 1
1, 2
1, 3
2, 0
2, 1
2, 2
2, 3
3, 0
3, 1
3, 2
3, 3

what i would like to do is randomly shuffle these x,y locations so that the "Dice" can end up in a random position when i shuffle the board. I apologize for not being clear but hopefully this makes sense.

Thank you
Last edited on
SO you want your dice array look like
 ` (0, 2) (3, 0) (1, 0) (2, 3) (0, 1) ... etc (completely random)`
If so, you can first make something like
 ``123456789101112131415161718`` ``````#include #include #include #include int main() { std::vector> values; /*initialize all combination*/ for(int i = 0; i < 4; ++i) for(int j = 0; j < 4; ++j) values.emplace_back(std::make_pair(i,j)); /*mix them randomly*/ std::random_shuffle(values.begin(),values.end()); /*output them to console*/ for(const auto& x: values) std::cout << '(' << x.first << ", " << x.second << ')' << std::endl; }``````

It gave me:
 ```(3, 0) (0, 1) (2, 1) (0, 2) (0, 0) (2, 3) (1, 3) (0, 3) (1, 0) (3, 3) (2, 0) (1, 1) (3, 2) (3, 1) (2, 2) (1, 2)```
Last edited on
Thank you
i have one last question about this, if i have 16 buttons how can i distribute these (x,y) locations randomly to all those buttons?
Thank you
Something along the lines of
 ``1234`` ``````for(int i = 0; i < values.size(); ++i) { buttons[i].x = values[i].first; buttons[i].y = values[i].second; }``````

Or alternatively you can create array of buttons before and then random_shuffle() it
Topic archived. No new replies allowed.