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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:06:50+00:00 2026-05-27T22:06:50+00:00

For testing purposes I need a function like this: /** * @param int $sizeInBytes

  • 0

For testing purposes I need a function like this:

/**
 *  @param int $sizeInBytes
 *
 * @returns string with random data
 */
function randomData($sizeInBytes)
{
 ...
}

Any ideas of a effective implementation? There is need for speed but not for real randomness (more a kind of “lorem ipsum”). My simplest idea would be to use real large file in the filesystem and fetch the required size by stream. But this needs at least a 100MB file. Is there a better way?

  • 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-05-27T22:06:50+00:00Added an answer on May 27, 2026 at 10:06 pm

    How about just creating a very long string if you have the memory available anyways?

    That should not take all that long 🙂

     $x = str_repeat(
         'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sollicitudin turpis ut augue lacinia at ullamcorper dolor condimentum. Nunc elementum suscipit laoreet. Phasellus vel sem justo, a vulputate arcu. Sed rutrum elit nec elit lobortis ultrices. Quisque elit nulla, rutrum et varius sit amet, pulvinar eget purus. Aliquam erat volutpat. Fusce turpis lectus, vestibulum sed ornare sed, facilisis sit amet lacus. Nunc lobortis posuere ultricies. Phasellus aliquet cursus gravida. Curabitur eu erat ac augue rutrum mattis. Suspendisse sit amet urna nec velit commodo feugiat. Maecenas vulputate dictum diam, eu tempor erat volutpat in. Donec id nulla tortor, nec iaculis nibh. Pellentesque scelerisque nisl sit amet ligula dictum commodo. Donec porta mi in lorem porttitor id suscipit lacus auctor.', 
         125000
     );
    

    You could of course just write that to a file one but creating it in memory doesn’t really take all that long.

    The code above produces an 98MB string in about 100ms and creating a 200MB string takes about 170ms on my box. That should be good enough for most cases.


    As noted in the comment below: You might have to change your php.ini setting if you limit the amount of memory your script is allowed to consume (or change it via memory_limit('...');). Also strings > 1.5gb might cause issues but thats not a concern here I’d say.

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

Sidebar

Related Questions

For testing purposes of a RandomGen -reliant function I need a RandomGen instance which
for testing purposes i need an recursive directory with some files, that comes to
For testing purposes I need to get my Outlook 2003 addin (vb.net) disabled so
For testing purposes I need to create sets of text files that have similar
For testing purposes I need my ABAP program to wait for few seconds. How
For testing purposes I have this shell script #!/bin/bash echo $$ find / >/dev/null
For testing purposes, I want to be able to create cookies as I need
I need a mock implementation of a class - for testing purposes - and
I need to make a request with a spoofed IP address for testing purposes.
For testing purposes I need to be sure that certain methods are not inlined

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.