Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How can I return a sequence of random numbers which dont repeat at all?
How can I return a sequence of random numbers which dont repeat at all?
✍: Guest
What you're looking for is often called a ``random permutation'' or ``shuffle.'' One way is to initialize an array with the values to be shuffled, then randomly interchange each of the cells with another one later in the array:
int a[10], i, nvalues = 10;
for(i = 0; i < nvalues; i++)
a[i] = i + 1;
for(i = 0; i < nvalues-1; i++) {
int c = randrange(nvalues-i);
int t = a[i]; a[i] = a[i+c]; a[i+c] = t; /* swap */
}
where randrange(N) is rand() / (RAND_MAX/(N) + 1)
2015-07-24, 1119👍, 0💬
Popular Posts:
Write out a function that prints out all the permutations of a string. For example, abc would give y...
Can you explain steps in function points? Below are the steps in function points: >First Count ILF, ...
How To Delete a User Account? - Oracle DBA FAQ - Managing Oracle User Accounts, Schema and Privilege...
If we have multiple AFTER Triggers on table how can we define the sequence of the triggers ? If a ta...
From performance point of view how do they rate ? Repeater is fastest followed by Datalist and final...