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,885 questions

51,811 answers

573 users

How to fill an array with 1 and 0 in random locations with Pascal

1 Answer

0 votes
program FillArrayWithRandom1and0Program;

uses
  SysUtils;

procedure FillArrayWithRandom1and0(var array_: array of Integer);
var
  i: Integer;
begin
  Randomize;
  for i := 0 to Length(array_) - 1 do
  begin
    array_[i] := Random(2); // Generates either 0 or 1
  end;
end;

var
  array_: array of Integer;
  i, size: Integer;
begin
  size := 10; // You can change the size of the array
  SetLength(array_, size);
  
  FillArrayWithRandom1and0(array_);

  // Print the array
  for i := 0 to Length(array_) - 1 do
  begin
    Write(array_[i], ' ');
  end;
  WriteLn;
end.




(*
run:

0 1 0 1 1 0 0 0 0 1 

*)

 



answered Jan 25, 2025 by avibootz

Related questions

...