optimize sample generation