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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:04:52+00:00 2026-06-02T16:04:52+00:00

Using Perl, without using any extra modules that don’t come with ActivePerl, how can

  • 0

Using Perl, without using any extra modules that don’t come with ActivePerl, how can I create a string of 8 characters from 0-F. example 0F1672DA? The padding should be controllable and exactly 8 characters is preferable.

More examples of the kinds of strings I would like to generate:

28DA9782
55C7128A
  • 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-02T16:04:52+00:00Added an answer on June 2, 2026 at 4:04 pm

    In principle, you ought to be able to do

    #!/usr/bin/env perl
    
    use strict; use warnings;
    
    for (1 .. 10) {
        printf "%08X\n", rand(0xffffffff);
    }
    

    However, you may find out that —at least on some systems with some perls (if not all)— the range of rand is restricted to 32,768 values.

    You can also study the source code of String::Random to learn how to generate random strings satisfying other conditions.

    However, my caution against using the built in rand on Windows system still stands. See Math::Random::MT for a high quality RNG.

    #!/usr/bin/env perl
    
    use strict; use warnings;
    
    my @set = ('0' ..'9', 'A' .. 'F');
    my $str = join '' => map $set[rand @set], 1 .. 8;
    print "$str\n";
    

    PS: The issue with Perl’s rand on Windows was fixed in 5.20:

    This meant that the quality of perl’s random numbers would vary from platform to platform, from the 15 bits of rand() on Windows to 48-bits on POSIX platforms such as Linux with drand48().

    Perl now uses its own internal drand48() implementation on all platforms. This does not make perl’s rand cryptographically secure. [perl #115928]

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

Sidebar

Related Questions

I have trouble using Perl grep() with a string that may contain chars that
Is it possible to check a bash script syntax without executing it? Using Perl,
From everything I've read on using Perl modules, the basic usage is: Module file
I have tried without success setting cookies using Perl CGI. My code looks like
I have the folling Perl script that I am using to import data directly
I am using a package in Perl (Biomart) that prints out the results of
I have application that works using Perl's CGI::Fast . Basically mainloop of the code
Using Perl, how do I check if a particular Windows process is running or
At work I'm using Perl 5.8.0 on Windows. When I first put Perl on,
I am using Perl to do text processing with regex. I have no control

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.