zufällig
by chance
Happening by chance; not planned or intended.
Ich habe meine alte Schulfreundin zufällig im Supermarkt getroffen.
I ran into my old school friend by chance at the supermarket.

random / by chance
Loading your saved state.
by chance
Happening by chance; not planned or intended.
Ich habe meine alte Schulfreundin zufällig im Supermarkt getroffen.
I ran into my old school friend by chance at the supermarket.

The word 'zufällig' (random/by chance) is derived from the noun 'der Zufall' (chance/coincidence). A 'Zufall' is an event that is not planned. So when something happens 'zufällig' (by chance), it happens 'durch Zufall' (by chance).
Was für ein Zufall, dass wir uns hier treffen!
What a coincidence that we're meeting here!
As an adverb, 'zufällig' (by chance/by any chance) can stand flexibly in the sentence. It often stands directly after the conjugated verb or at the beginning of the sentence to emphasize that the event was unplanned.
Ich habe zufällig noch ein Ticket übrig.
I happen to have one ticket left.
In questions, 'zufällig' (by any chance) is used to make the question more indirect and polite. It signals that you understand the other person may not know the answer.
Haben Sie zufällig einen Stift für mich?
Do you happen to have a pen for me?
In the meaning 'unbeabsichtigt' (unintentional/by chance), 'zufällig' (by chance) is often combined with verbs of perception or encounter. Typical are: 'jemanden zufällig treffen' (to meet someone by chance), 'etwas zufällig sehen' (to see something by chance), or 'etwas zufällig hören' (to hear something by chance).
Beim Spaziergang habe ich zufällig einen alten Freund getroffen.
On my walk, I met an old friend by chance.
The meaning 'stochastisch' (stochastic) belongs to the technical language of mathematics and statistics. In everyday language, 'zufällig' (random) is almost never used in this exact sense.
Die Testgruppe wurde durch eine zufällige Auswahl bestimmt.
The test group was determined through random selection.
maybe
'vielleicht' and 'zufällig' can both make a question softer and less direct. In questions like 'Hast du vielleicht Zeit?' (Do you perhaps have time?) or 'Hast du zufällig Zeit?' (Do you happen to have time?), both sound polite. The difference is: 'vielleicht' generally expresses uncertainty or possibility. 'zufällig' can additionally mean that something happens without being planned. That is why 'zufällig' fits especially well when you do not expect the other person to know or have something. Learners may confuse the words because both can have a similar effect in polite questions. Outside such questions, however, they are not the same: 'Vielleicht regnet es' means only that rain is possible; 'zufällig' would not fit here.

Hast du zufällig noch einen Stift in deiner Tasche?
Do you happen to still have a pen in your bag?
Vielleicht hat Sofia vor dem Termin noch Zeit für einen kurzen Anruf.
Maybe Sofia still has time for a quick call before the appointment.