Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • gprakhar
    Member
    • Aug 2010
    • 78

    CNV Simulator -- Random Number Generation

    Hello,

    I have written a program to simulate CNV, into the reference genome.

    It take the Reference Genome/Chromosome as input. The program then generates a Random number(X), copies the segment from that position(X), size specified by user.
    Then generates another random number(Y), and inserts the copied segment from X position, at Y position. The output is the modified input file with inserted CNV and a txt file with Location of CNVs ie. position where copied from (X) and where Inserted (Y).

    I give the Random Number generation function MIN and MAX value. MIN =1 and MAX=last Position(Size), it then generates a Random number within these limits.
    Problem is, with same input(MIN & MAX) the random numbers generated is same. eg. If I make my program run once and generate 100 numbers, they are random. But if I generate 100 numbers by running the program again, the numbers are same as before.

    CODE:
    //call this function first to seed
    void initialize_rand(){
    srand((unsigned)(time(0)));
    }

    //generates a psuedo-random integer between min and max
    long int randint(long int min, long int max){
    if(min>max){
    return lrand48()%(min-max)+max;
    }
    else{
    return lrand48()%(max-min)+min;
    }
    }
  • gprakhar
    Member
    • Aug 2010
    • 78

    #2
    PS

    I know this is not a C programming forum.
    Googled the problem, but didn't find anything useful.
    But as many of the member here have dealt with similar situation, hence I thought of asking here.

    Comment

    • simonandrews
      Simon Andrews
      • May 2009
      • 870

      #3
      Originally posted by gprakhar View Post
      Problem is, with same input(MIN & MAX) the random numbers generated is same. eg. If I make my program run once and generate 100 numbers, they are random. But if I generate 100 numbers by running the program again, the numbers are same as before.
      If that's happening then it means your RNG is using the same seed value each time. I'm not a C programmer but I suspect that time(0) returns the same value each time and that you probably want to use time(NULL) to get the current time value so the seed is different each time.

      Comment

      • quinlana
        Senior Member
        • Sep 2008
        • 119

        #4
        Your issue is likely that the time() function has granularity to the second. If you make multiple calls to you program in the same second, the results will be identical. The following will seed based on time and process_id on POSIX systems. Therefore, for a given boot cycle, you are guaranteed not to have redundant seeds

        Code:
        srand((unsigned)time(0)+(unsigned)getpid())
        You'll need to include the following fir getpud():

        Code:
        #include <unistd.h>
        Last edited by quinlana; 01-28-2011, 11:20 AM. Reason: typo

        Comment

        • gprakhar
          Member
          • Aug 2010
          • 78

          #5
          Solved

          Thank you everyone for the reply.

          I made the change suggested by "quinlana".
          Also changed the seeding function to srand48().
          Every thing is working fine now.

          Comment

          • adurasiwam3
            Member
            • Apr 2012
            • 12

            #6
            is your program available for download? i would like to generate simulated CNV

            Comment

            Latest Articles

            Collapse

            • SEQadmin2
              From Collection to Sequencing: Why Sample Preparation and Preservation Define Sequencing Data
              by SEQadmin2


              Data variability is still an issue in sequencing technologies despite the advances in reproducibility and accuracy of these platforms. But the problem does not originate in the sequencing itself, but in the previous steps, before the sample reaches the sequencer.


              The first step is collection, followed by preservation and sample preparation for analysis. Most scientists overlook those steps, but not being careful might just be skewing the experiment’s results.
              ...
              Yesterday, 10:05 AM
            • SEQadmin2
              Single-Cell Sequencing at an Inflection Point: Early Impacts of New Platforms and Emerging Trends
              by SEQadmin2


              With the launch of new single-cell sequencing platforms in 2026, the field stands at an exciting inflection point. This article surveys the most impactful advances in the field and discusses how they’re reshaping research in cancer, immunology, and beyond.


              Introduction

              Single-cell sequencing technologies have undergone remarkable advances over the past decade, transitioning from low-throughput experimental approaches to highly scalable platforms capable of...
              05-22-2026, 06:42 AM
            • SEQadmin2
              Environmental Genomics in the Age of NGS: From Microbes to Conservation Strategies
              by SEQadmin2

              Studying ecosystems means dealing with complex, multi-species communities that are hard to observe at scale. This complexity, however, hides many important questions to be answered, from how biogeochemical cycles work and how climate change can affect species distribution to how conservation strategies can work best.


              Genomics, particularly since the expansion of NGS, has transformed ecosystem ecology. By sequencing environmental DNA, we can now assess biodiversity without direct...
              05-06-2026, 09:04 AM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by SEQadmin2, Yesterday, 12:03 PM
            0 responses
            17 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, Yesterday, 11:40 AM
            0 responses
            13 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 05-28-2026, 11:40 AM
            0 responses
            29 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 05-26-2026, 10:12 AM
            0 responses
            31 views
            0 reactions
            Last Post SEQadmin2  
            Working...