Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8372183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:21:39+00:00 2026-06-09T14:21:39+00:00

I have to sample a certain number of objects from a population. The following

  • 0

I have to sample a certain number of objects from a population. The following piece of code gives the sampling with replacement. What condition can I use for the sampling without replacement?

do while(j .lt. w)
   call random_number(u1)
   j1 = 1 + int(population*u1)
   Z = inftime(j1)
   Z1 = X(j1)
   Z2 = Y(j1)
   do t = 1, 10
      if(Z.gt.0 .and. Z.le.10)then
         if(t==Z .and.( my_cnt(t) .lt. k1(t)))then
            my_cnt(t) = my_cnt(t) + 1
            j = j+1
            inftime1(j)= Z 
            X1(j) = Z1
            Y1(j) = z2
         endif
      endif
   enddo
enddo

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:21:41+00:00Added an answer on June 9, 2026 at 2:21 pm

    If I understand correctly you use the statements

       call random_number(u1)
       j1 = 1 + int(population*u1)
    

    to generate an integer index (j1) to select the j1-th element of a population. I’m going to call that the i-th element out of a population of n. At each iteration of the loop you generate a new random number and select a new i-th element, with some probability that it is the same element as you have chosen in one (or more) previous iterations. You’d rather have an approach that avoids re-selecting an already-selected i. I think you have at least 3 approaches.

    One: Keep a list of the i‘s you’ve already used. If the random number generator throws up the same i in a later iteration, throw the dice again until you get a new one. This requires a little straightforward book-keeping. If you need help programming this, edit your question. This method begins to lose its appeal as the proportion of already-selected i‘s grows large. One you’ve selected 50% of the members of the population you’ll have to roll the dice twice (on average) for each new i. You can decide whether or not this is a serious issue for you.

    Two: Create a random permutation of the populations; in the first iteration choose the first of the populations (in their new random order), in the second the second, and so on. Of course you wouldn’t really permute the populations, you’d create a random permutation of the indices into the populations. This Wikipedia article suggests how you might create such a random permutation. Again, if you have trouble coding this, edit your question, or ask a new one.

    Three: This is a variation on Two and is what I would do. First, outside the loop, create an array of n random numbers:

    real, dimension(n) :: random_array
    .
    .
    call random_number(random_array)
    

    Next, inside the loop, find the index of the smallest value in the array:

    j1 = minloc(random_array, dim=1)
    

    Note that I’ve gone back to your notation and used j1 as the index for the population. Note also the specification of dim=1 on the call to minloc to ensure that it returns a scalar: I think this is Fortran 2003 semantics and earlier implementations may return a rank-1 array with 1 element so check your compiler documentation.

    If minloc finds 2 (or more) elements in the array with the same value, relatively unlikely since they are reals, it just returns the index of the first one it finds, which is OK for our purposes.

    Next, to ensure that we don’t choose the same index at the next iteration, do this:

    random_array(j1) = huge(1.0)
    

    taking care to ensure that the argument to the call to huge is of the same type and kind as the real numbers in the random_array.

    This should enumerate the elements of the population randomly without replacement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does any one have sample code to apply phone number formatting to certain fields???
Does anyone have sample code, or a tutorial which demonstrates how to use Grappa
I have developed sample api as jar file. This jar file contains the code
If I have the following 3 documents. How can I select the documents that
I have very large dataframe and I need to choose variable number satisfying certain
We have a simple requirement to use https for certain specific pages in a
I have a simple query that finds cities that are within a certain distance
I have a (simple) sitemap and am trying to figure out why a certain
Hi guys I have made a JqueryUI simple slider,on certain value range I make
Pretty simple question. I'm quite certain I have the Class, method, codebehind, etc linked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.