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 8283613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:47:43+00:00 2026-06-08T10:47:43+00:00

As I understand it, Random.Next() uses the system time for getting the seed, but

  • 0

As I understand it, Random.Next() uses the system time for getting the seed, but when iterating through a loop very fast the system time hasn’t changed or has hardly changed, giving me the same “random” number. I’m attempting to use random to select starting positions to begin writing bytes for about 2 seconds of static here and there to music files, 30 different positions are selected, but they’re almost the same. I’m getting almost continuous static from the beginning, broken about 3 times for just a few seconds before it resumes playing the music normally at around 30 seconds in; which isn’t what I want, I need it spread out throughout the entire clip. “int pos” is the problem, its not random, each starting position is nearly identical to all the others, so I have a prolonged amount of static, not static randomly spread throughout the music. My randoms are also static.

FileStream stream = new FileStream(file, FileMode.Open, FileAccess.ReadWrite);
for (int i = 0; i < 20; i++)
{
    int pos = rand2.Next(75000, 4000000 /*I've been too lazy to get the file length, so I'm using 4000000*/ );
    for (int x = 0; x < 500000/*500000 is a little over 2 seconds of static*/; x++)
    {
        byte number = array[rand.Next(array.Length)];
        stream.Position = pos;
        pos++;
        stream.WriteByte(number); 
    }
}

I assumed that it would take 5 seconds or so to make each write (on my slow CPU), which would be enough time for the next random to give me a position that isn’t identical to or extremely close to the previous one. As it stands, each time I seem to be getting an initial position of about ~90000 (first few seconds of music); and all of the next ones are within 20 seconds of that. So my question is, what do I need to modify/do differently in order to achieve my desired result? I’d like a couple seconds of static scattered throughout the entire clip, not clustered together.

I have a byte array which stores my hex digits, which are randomly selected, that appears to work fine, its just the randomness of the writing positions isn’t random at all, they’re all in extreme proximity.

byte[] array = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F };

Thanks.

P.S. I know I should have using blocks for the FileStream, I’ll add it when I get around to it.

  • 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-08T10:47:46+00:00Added an answer on June 8, 2026 at 10:47 am

    If 500000 bytes is about 2 seconds of audio, and you’re starting somewhere between 75000 and 4000000, you’re starting between 0.15s and 8s into the song. That explains why you’re not hearing any static after about 10s into the song. Try using the actual file size (minus 500000) as the upper bound of the rand.Next call used to populate pos.

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

Sidebar

Related Questions

I understand that time(0) is commonly using for seeding random number generators and that
I understand this is an easy question but for some reason this just isn't
I understand what weak tables are. But I'd like to know where weak tables
I am getting weird problem, the crash happens at random times, for example i
I'm creating some random classes to understand Polymorphism better. Coding is as follows: Poly1
I read about skipList implementation in C++ and I don't understand this random function
Could someone help me understand how to preload the images from random.php page so
Basically I want to generate random numbers that won't ever repeat for a very
While trying to understand how refp's solution for random hash value selection works, I
I understand what a double exclamation mark does (or I think I understand) but

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.