Re: Random numer generation without repetition



"Jos (10584) " <#10584@xxxxxxxxxxxxxxxx> wrote in message <helfr2$soh$1@xxxxxxxxxxxxxxxxxx>...
"uri " <sshangover@xxxxxxxxxxx> wrote in message <helbpn$krj$1@xxxxxxxxxxxxxxxxxx>...
TideMan <mulgor@xxxxxxxxx> wrote in message <9983dcb2-dc04-45fe-af74-71e66d7a9871@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>...
On Nov 26, 8:25?pm, "uri " <sshango...@xxxxxxxxxxx> wrote:
"Matt Fig" <spama...@xxxxxxxxx> wrote in message <gsv7cj$oj...@xxxxxxxxxxxxxxxxxx>...
Check out randperm.

nice approach but not good enough, I need a small number of elmennts reletively to the maximum sampling size. if I'd use randperm it'll blow my memory

Huh???
tic;y=randperm(200);toc
Elapsed time is 0.001623 seconds.

Did you read the help correctly?
Or is there something that you're not telling us?

let's say I have a vector (file wise) on my harddisk which has 10^8 cells
I"d like to sample m elements out of this vector but using:
gen=randperm(10^8);
x=gen(1:m);
gen is too big
I just need the m elements without generating all the 10^8 numbers

if m << 10^8 you could just use a simple trial and error approach:

n = 1e8 ;
m = 200;
tic ;
Done = false ;
j = 0 ;
while ~Done,
j = j + 1 ;
R = ceil(n*rand(m,1)) ;
Done = numel(unique(R))==m ;
end
fprintf('\nFound %d unique elements between 1 and %.0e\n in %.2fs,in %d trial(s)\n',m,n,toc,j) ;


Jos

Exactly. When the sample size is small, just reject
those samples that would have seen a repeat, and
redo the few that fail.

Of course, if the sample size is too large, then this
loop will essentially never terminate. So you need
to be careful there. A simple, lazy, scheme might
use a limit on the number of times the above while
loop will be allowed to run. If it fails without success
after say 5 times, then try a different method to
generate the samples.

John
.



Relevant Pages

  • Re: Innovative Systems FPE...
    ... window so one could loop using one register for copy in/out but I ... suppose you can simply unroll the loop. ... I mean't swap the order of the bytes in the hardware ... would be a graphical memory map, but even then, I usually rotate it ...
    (comp.sys.apple2)
  • Re: Fast string operations
    ... > is why people use unsafe code now and then to use pointer arithmetic to ... > loop over arrays without all the unnecessary bounds checking. ... don't return the trimmed string". ... The customer perceives this as a memory leak. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Performance Improvement of complex data structure (hash of hashes of hashes)
    ... Anno Siegel wrote: ... >> Here is the code that I'm using to build up this data structure. ... loop through and increment the ... I know that memory allocation in C is expensive, ...
    (comp.lang.perl.misc)
  • Re: Errors locking offscreen surface if application heap is large
    ... whats the memory map for the machines, ... > few different memory configs, and a few different graphics card configs, and ... >> In these conditions I see calls to Lock a plain offscrreen surface fail ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Cost of calling a standard library function
    ... It accesses/reads memory using esi 4 ... > safly move it within the cache, without having to go via ebx. ... try it the same thing on a different earlier CPU, ... should check it out...for "tight inner loop" stuff, ...
    (alt.lang.asm)