How to Generate Array of Random Integers

asked 2014-02-25 11:14:31 -0500

SandeepP gravatar image

updated 2014-02-25 11:17:36 -0500

I am a newbie in using OpenCV. I am trying to generate a column vector (say of size 10x1) initialized to zeros and fill five randomly selected elements of this vector with some non-zero values. To choose the five random indices, I have to generate an array of 5 integers, in which, each element ranging between 0-9. Then I can fill some non-zero value at each of these randomly generated positions. Is there some way to generate an array of random integers in which the range of integers can be restricted.? Of course I can go ahead with the brute force approach by picking the elements one by one, but when I use in the real situation, the matrix dimensions will be larger and I think it will be tedious job to do it using a loop. I was checking to see some direct methods like randn() or randu().

edit retag flag offensive close merge delete