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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,845 questions

51,766 answers

573 users

How to initialize char array with random characters in Pascal

2 Answers

0 votes
program RandomCharArray;

const
  ArraySize = 10; // Size of the char array
var
  charArray: array[1..ArraySize] of Char;
  i: Integer;
begin
  Randomize; // Initialize random number generator
  for i := 1 to ArraySize do
  begin
    // Generate a random character (from 'A' to 'Z')
    charArray[i] := Chr(Random(26) + Ord('A'));
  end;

  for i := 1 to ArraySize do
    Write(charArray[i], ' ');
end.



(*
run:

W J J B K N M X R G 

*)

 



answered Mar 11, 2025 by avibootz
0 votes
program RandomCharArray;

const
  SIZE = 10; // Array size
  CHARACTERS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var
  charArray: array[1..SIZE] of Char;
  i: Integer;

procedure InitializeCharArrayWithRandomCharacters(var arr: array of Char);
var
  j: Integer;
  randomIndex: Integer;
begin
  Randomize; // Initialize random number generator
  for j := Low(arr) to High(arr) do
  begin
    randomIndex := Random(Length(CHARACTERS)) + 1; // Generate a random index
    arr[j] := CHARACTERS[randomIndex];
  end;
end;

begin
  // Initialize the character array with random characters
  InitializeCharArrayWithRandomCharacters(charArray);

  for i := 1 to SIZE do
    Write(charArray[i], ' ');
end.



(*
run:

Y S 1 O C 9 x H j j 

*)

 



answered Mar 11, 2025 by avibootz
edited Mar 12, 2025 by avibootz

Related questions

2 answers 92 views
3 answers 105 views
1 answer 73 views
73 views asked Jan 16, 2025 by avibootz
1 answer 143 views
143 views asked Aug 17, 2022 by avibootz
1 answer 222 views
...