def sample(self, batch_size, batch_idxs=None):
<EOL>assert self.nb_entries >= self.window_length + <NUM_LIT:2>, '<STR_LIT>'<EOL>if batch_idxs is None:<EOL><INDENT>batch_idxs = sample_batch_indexes(<EOL>self.window_length, self.nb_entries - <NUM_LIT:1>, size=batch_size)<EOL><DEDENT>batch_idxs = np.array(batch_idxs) + <NUM_LIT:1><EOL>assert np.min(batch_idxs) >= self.window_length + <NUM_LIT:1><EOL>assert np.max(batch_idxs) < self.nb_entries<EOL>assert len(batch_idxs) == batch_size<EOL>experiences = []<EOL>for idx in batch_idxs:<EOL><INDENT>terminal0 = self.terminals[idx - <NUM_LIT:2>]<EOL>while terminal0:<EOL><INDENT>idx = sample_batch_indexes(self.window_length + <NUM_LIT:1>, self.nb_entries, size=<NUM_LIT:1>)[<NUM_LIT:0>]<EOL>terminal0 = self.terminals[idx - <NUM_LIT:2>]<EOL><DEDENT>assert self.window_length + <NUM_LIT:1> <= idx < self.nb_entries<EOL>state0 = [self.observations[idx - <NUM_LIT:1>]]<EOL>for offset in range(<NUM_LIT:0>, self.window_length - <NUM_LIT:1>):<EOL><INDENT>current_idx = idx - <NUM_LIT:2> - offset<EOL>assert current_idx >= <NUM_LIT:1><EOL>current_terminal = self.terminals[current_idx - <NUM_LIT:1>]<EOL>if current_terminal and not self.ignore_episode_boundaries:<EOL><INDENT>break<EOL><DEDENT>state0.insert(<NUM_LIT:0>, self.observations[current_idx])<EOL><DEDENT>while len(state0) < self.window_length:<EOL><INDENT>state0.insert(<NUM_LIT:0>, zeroed_observation(state0[<NUM_LIT:0>]))<EOL><DEDENT>action = self.actions[idx - <NUM_LIT:1>]<EOL>reward = self.rewards[idx - <NUM_LIT:1>]<EOL>terminal1 = self.terminals[idx - <NUM_LIT:1>]<EOL>state1 = [np.copy(x) for x in state0[<NUM_LIT:1>:]]<EOL>state1.append(self.observations[idx])<EOL>assert len(state0) == self.window_length<EOL>assert len(state1) == len(state0)<EOL>experiences.append(Experience(state0=state0, action=action, reward=reward,<EOL>state1=state1, terminal1=terminal1))<EOL><DEDENT>assert len(experiences) == batch_size<EOL>return experiences<EOL>
Return a randomized batch of experiences

        # Argument
            batch_size (int): Size of the all batch
            batch_idxs (int): Indexes to extract
        # Returns
            A list of experiences randomly selected