Skip to content

Commit da0b7b5

Browse files
committed
Revert change to use native random number generation
1 parent 2af89fe commit da0b7b5

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/read_mismatchbam_cpp.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <Rcpp.h>
1212
#include <cli/progress.h>
1313
#include "utils.h"
14-
#include <random>
1514

1615
#define MISMATCHBAM_MODE_READ 1
1716
#define MISMATCHBAM_MODE_STATE 3
@@ -528,14 +527,6 @@ Rcpp::List read_mismatchbam_cpp(std::string inname_str,
528527
// ... return value for mode 3
529528
Rcpp::NumericMatrix pair_counts;
530529

531-
// random number generation
532-
// first generate a single random number from R
533-
// to link the C++ RNG to the R session's current seed state
534-
// dis() can then be used to draw uniformly distributed random numbers
535-
double r_seed = R::runif(0, 1000000);
536-
std::mt19937 gen((unsigned int)r_seed);
537-
std::uniform_real_distribution<double> dis(0.0, 1.0);
538-
539530
// prepare bam file for reading
540531
if (verbose) {
541532
snprintf(buffer, buffer_len, "opening input file {.file %s} using {%d} thread{?s}", inname, n_threads);
@@ -614,7 +605,7 @@ Rcpp::List read_mismatchbam_cpp(std::string inname_str,
614605
(calculate_aligned_bases(bamdata) >= minAlignedLength)) {
615606

616607
if (!(bamdata->core.flag & BAM_FPAIRED) &&
617-
((n_alns_to_sample == 0) || (dis(gen) < keep_aln_fraction))) {
608+
((n_alns_to_sample == 0) || (R::runif(0, 1) < keep_aln_fraction))) {
618609
// single-end - process directly
619610
success = process_mismatch_bam_record(
620611
MISMATCHBAM_MODE_STATE, // run mode
@@ -674,7 +665,7 @@ Rcpp::List read_mismatchbam_cpp(std::string inname_str,
674665
// mate seen - get it from the map and process the pair
675666
bamdata2 = curr_records_it->second;
676667

677-
if ((n_alns_to_sample == 0) || (dis(gen) < keep_aln_fraction)) {
668+
if ((n_alns_to_sample == 0) || (R::runif(0, 1) < keep_aln_fraction)) {
678669
success = process_mismatch_bam_record_pair(
679670
MISMATCHBAM_MODE_STATE, // run mode
680671
bamdata2, // bam record
@@ -722,7 +713,7 @@ Rcpp::List read_mismatchbam_cpp(std::string inname_str,
722713
curr_records_it = curr_records.begin();
723714
bamdata2 = curr_records_it->second;
724715

725-
if ((n_alns_to_sample == 0) || (dis(gen) < keep_aln_fraction)) {
716+
if ((n_alns_to_sample == 0) || (R::runif(0, 1) < keep_aln_fraction)) {
726717
success = process_mismatch_bam_record(
727718
MISMATCHBAM_MODE_STATE, // run mode
728719
bamdata2, // bam record
@@ -813,7 +804,7 @@ Rcpp::List read_mismatchbam_cpp(std::string inname_str,
813804
// read overlapping alignments using iterator
814805
while ((c = sam_itr_next(infile, iter, bamdata)) >= 0) {
815806
if (!(bamdata->core.flag & (BAM_FUNMAP | BAM_FSECONDARY | BAM_FSUPPLEMENTARY)) &&
816-
((n_alns_to_sample == 0) || (dis(gen) < keep_aln_fraction))) {
807+
((n_alns_to_sample == 0) || (R::runif(0, 1) < keep_aln_fraction))) {
817808
success = process_mismatch_bam_record(
818809
MISMATCHBAM_MODE_READ, // run mode
819810
bamdata, // bam record

0 commit comments

Comments
 (0)