K
Keith Thompson
[...]RoSsIaCrIiLoIA said:#define U unsigned
#define F for
#define W while
#define R return
#define os cout <<
#define is cin >> [...]
/* it is a c++ main */
Please stop wasting our time.
[...]RoSsIaCrIiLoIA said:#define U unsigned
#define F for
#define W while
#define R return
#define os cout <<
#define is cin >> [...]
/* it is a c++ main */
RoSsIaCrIiLoIA said:.... snip ...
/* C++ and C but you use a C++ compiler and try ... */
#include <iostream.h>
#include <stdlib.h>
#include <limits.h>
#include <time.h>
#define U unsigned
#define F for
#define W while
#define R return
#define os cout <<
#define is cin >>
int main(void)
{unsigned a[100] = {0}, i;
ArrRand( a, (sizeof a)/(sizeof *a), 80000000);
for( i = 0; i < 99; ++i)
cout << " " << a;
cout << "\n";
return 0;
}
Grumble said:Tools - Message Filters
Sender contains "Default User"
Action = Mark read or Delete or ...
RoSsIaCrIiLoIA said:Mine can
generate all of them, although I suspect the probability distribution
may be different.
thank you
but seems to me there are odd results e.g.
if rand_array is like you suggest =>
inserisci il massimo[0 finisce]> 888888888
inserisci il numero di elementi> 20
312557105 548251158 760618515 876091816 886173925 888503572 888804673
888826177
888871515 888882642 888884513 888885725 888887085 888888029 888888553
888888700
888888768 888888843 888888873 888888877
inserisci il massimo[0 finisce]> 0
rand_array1 seems 'ok'
inserisci il massimo[0 finisce]> 99
inserisci il numero di elementi> 98
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
26 27 28 29
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
53 54 55 5
6 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
80 81 82
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
U intervallo(U a, U b)
{R a + (U) _lrand() % (b-a);}
U rand_array1( U* a, U size, U sup_val )
{static int i = 1;
unsigned j, k, h;
/*---------------------*/
if( a==0 || size<2 || sup_val<=size )
return 0;
if(i)
{i = 0; srand(time(0));}
k = sup_val / size;
a[0] = (k<=1 ? 0 : (U) _lrand() % k);
for( j = 1; j<size; ++j)
a[j] =
(a[j-1]+1 >= (h=j*k)
? a[j-1] + 1
: intervallo( a[j-1] + 1, h)
);
R 1;
}
josh said:Another possibility might be to choose the middle element in the array
and then recursivly fill the top and bottom halves, using a similar
method for selecting the upper and lower bounds. Or this can probably
be done iteritavely, but it would take more thought. Either way it'd
still take O(N) time.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.