If program is run multiple times within the same second - in loop, rand() will generate the same value because we're seeding with the same value. I am getting same values. Is there any way to fix this ?
Instead of running the program twice, you could call the function twice in the same program. On the second function call, the random values should be different. If this is not possible, there are other ways to create a seed that do not rely on the current time, for example: stackoverflow.com/a/7617612 stackoverflow.com/a/7617686
create 3 x3 matrixin 2 d array.each cell of a matrix is filled with unique random no between 1 to 50(use random function).the user can see random value hiden in matrx
This video shows how to fill a 1D array with unique random numbers: th-cam.com/video/wnjYD_euSJQ/w-d-xo.html. One easy way to fill a 2D array would be to generate the unique numbers in a 1D array that is m x n in length, where m is the number of rows and n is the number of columns in the 2D array, then you could just copy the values over to the 2D array in a loop nested in a loop like this: int k = 0; for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) array2d[i][j] = array1d[k++]; This would essentially let you use the code in the video I linked to above. Otherwise, you could do it in a way that is pretty similar to the solution I linked to above, but you would need a loop nested in a loop setting each value, and another loop nested in a loop to check if the new random value to see if it is in the previous values. Maybe one day I can make a video on that. :-)
I am hoping to do a video on that topic one day Furkan! :-) In the meantime I have this video on doing this with 1D arrays that might give you some ideas: th-cam.com/video/wnjYD_euSJQ/w-d-xo.html
Amazing video thank you
If program is run multiple times within the same second - in loop, rand() will generate the same value because we're seeding with the same value. I am getting same values. Is there any way to fix this ?
Instead of running the program twice, you could call the function twice in the same program. On the second function call, the random values should be different.
If this is not possible, there are other ways to create a seed that do not rely on the current time, for example:
stackoverflow.com/a/7617612
stackoverflow.com/a/7617686
I made this video to answer your question. :-) I hope you enjoy it: th-cam.com/video/zHZx9ByTo2s/w-d-xo.html
create 3 x3 matrixin 2 d array.each cell of a matrix is filled with unique random no between 1 to 50(use random function).the user can see random value hiden in matrx
Did this video help you with this question, or are you stuck on it?
This is usefull, thanks bro
You're welcome! :-D
what if i don't want to repeat numbers?
This video shows how to fill a 1D array with unique random numbers: th-cam.com/video/wnjYD_euSJQ/w-d-xo.html.
One easy way to fill a 2D array would be to generate the unique numbers in a 1D array that is m x n in length, where m is the number of rows and n is the number of columns in the 2D array, then you could just copy the values over to the 2D array in a loop nested in a loop like this:
int k = 0;
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
array2d[i][j] = array1d[k++];
This would essentially let you use the code in the video I linked to above.
Otherwise, you could do it in a way that is pretty similar to the solution I linked to above, but you would need a loop nested in a loop setting each value, and another loop nested in a loop to check if the new random value to see if it is in the previous values. Maybe one day I can make a video on that. :-)
@@PortfolioCourses thanks, i will try it
@@Roadieroundup You're welcome! 🙂
Please make a video of 2D array filled with unique random values 🙏
I am hoping to do a video on that topic one day Furkan! :-) In the meantime I have this video on doing this with 1D arrays that might give you some ideas: th-cam.com/video/wnjYD_euSJQ/w-d-xo.html
thanks mate
You're welcome Abdullah! 🙂
whatever anything I do or did or anything or know or knew or did not know or knew
did not knew