Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,943 questions

55,787 answers

573 users

How to generate a random RGBA color and opacity in Pascal

1 Answer

0 votes
program RandomRGBA;

{$mode delphi}{$H+}

{
    Generate a random RGBA color string.
    Produces full‑range RGB values and a floating‑point opacity.
}

uses
    SysUtils;  { for Format() }

// Generate a random integer in the range [0..255] 
function RandomChannel: Integer;
begin
    Result := Random(256);
end;

// Generate a random opacity in the range [0..1] 
function RandomOpacity: Double;
begin
    Result := Random;  { Random returns a float in [0..1) }
end;

// Create a random RGBA color string 
function RandomRGBAString: String;
var
    r, g, b: Integer;
    a: Double;
begin
    r := RandomChannel();
    g := RandomChannel();
    b := RandomChannel();
    a := RandomOpacity();

    { Format as rgba(r, g, b, a) with two decimal places }
    Result := Format('rgba(%d, %d, %d, %.2f)', [r, g, b, a]);
end;

var
    color: String;

begin
    Randomize;  { ensure different results each run }

    color := RandomRGBAString;
    WriteLn(color);
end.


{
run:

rgba(233, 61, 100, 0.92)

}

 



answered 6 days ago by avibootz
...