# Can computer viruses form randomly from computer code?

**URL:** <https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930>\
**Category:** Factual Questions\
**Created:** [June 28, 2018, 5:03pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930 "2018-06-28T17:03:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Czarcasm](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/czarcasm/32/4050_2.png) [@Czarcasm](https://boards.straightdope.com/u/Czarcasm)\
**Post date:** [June 28, 2018, 5:03pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/1 "2018-06-28T17:03:01Z")

</div>

Inspired by [this thread.](https://boards.straightdope.com/sdmb/showthread.php?t=857660)😃  
I’m not talking about a poorly written program that does what the writer didn’t intend it to do, but bits of random coding interacting to form computer virus.  
I don’t know much about programming, so if this is a stupid question, let me know.

---

<div class="post-metadata">

**Author:** ![DPRK](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DPRK](https://boards.straightdope.com/u/DPRK)\
**Post date:** [June 28, 2018, 5:12pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/2 "2018-06-28T17:12:01Z")

</div>

A poorly-written program could crash the system, fill up the disk, cause data loss, etc., but it is not going to replicate itself by deliberately infecting other programs and executable files. There is no evolutionary process or natural selection going on to produce such programs. Computer viruses are written by hand by hackers and researchers and also by criminals.

---

<div class="post-metadata">

**Author:** ![GreenWyvern](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/greenwyvern/32/2834_2.png) [@GreenWyvern](https://boards.straightdope.com/u/GreenWyvern)\
**Post date:** [June 28, 2018, 5:34pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/3 "2018-06-28T17:34:04Z")

</div>

Can thread viruses on a message board form by random combinations of bits of decaying threads?

🙂

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [June 28, 2018, 5:50pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/4 "2018-06-28T17:50:23Z")

</div>

In theory, yes.  
The data on a hard disk could get corrupted by a power failure in such a way that it created a new, functional program.  
In practice, though, the chance of that happening is roughly the same as the chance that you will win the lottery one million times in a row.

---

<div class="post-metadata">

**Author:** ![AHunter3](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ahunter3/32/368_2.png) [@AHunter3](https://boards.straightdope.com/u/AHunter3)\
**Post date:** [June 28, 2018, 7:11pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/5 "2018-06-28T19:11:30Z")

</div>

Yeah, it’s possible in the same sense that a roomful of monkeys banging on typewriter keyboards will replicate a Shakespearean sonnet. OK, probably a bit more likely than that, since a self-replicating code snippet could be pretty short, but still very farfetched.

---

<div class="post-metadata">

**Author:** ![drachillix](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@drachillix](https://boards.straightdope.com/u/drachillix)\
**Post date:** [June 28, 2018, 7:34pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/6 "2018-06-28T19:34:54Z")

</div>

> [@beowulff](#):
>
> In theory, yes.  
> The data on a hard disk could get corrupted by a power failure in such a way that it created a new, functional program.  
> In practice, though, the chance of that happening is roughly the same as the chance that you will win the lottery one million times in a row.

Or that a bomb going off in your pantry would create a dish worth of a Michelin star.

---

<div class="post-metadata">

**Author:** ![Colibri](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/colibri/32/1841_2.png) [@Colibri](https://boards.straightdope.com/u/Colibri)\
**Post date:** [June 28, 2018, 8:41pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/7 "2018-06-28T20:41:44Z")

</div>

> [@Czarcasm](#):
>
> Inspired by [this thread.](https://boards.straightdope.com/sdmb/showthread.php?t=857660)😃  
> I’m not talking about a poorly written program that does what the writer didn’t intend it to do, but bits of random coding interacting to form computer virus.  
> I don’t know much about programming, so if this is a stupid question, let me know.

**Moderator Note**

It’s misplaced in General Questions, since you’ve been around long enough to know that parody threads belong in the Pit. This is closed. Don’t do this again.

Colibri  
General Questions Moderator

---

<div class="post-metadata">

**Author:** ![Colibri](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/colibri/32/1841_2.png) [@Colibri](https://boards.straightdope.com/u/Colibri)\
**Post date:** [June 28, 2018, 8:47pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/8 "2018-06-28T20:47:45Z")

</div>

> [@Colibri](#):
>
> **Moderator Note**
> 
> It’s misplaced in General Questions, since you’ve been around long enough to know that parody threads belong in the Pit. This is closed. Don’t do this again.
> 
> Colibri  
> General Questions Moderator

After a PM from the OP, I have reopened the thread. It appeared to be suggesting that the question it was based on was stupid.

---

<div class="post-metadata">

**Author:** ![Sunny\_Daze](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/sunny_daze/32/438_2.png) [@Sunny\_Daze](https://boards.straightdope.com/u/Sunny_Daze)\
**Post date:** [June 28, 2018, 8:52pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/9 "2018-06-28T20:52:30Z")

</div>

I can see why someone might ask this, but unless someone had programmed the code to behave in this manner, no, this could not happen.

ETA: there may be a question of semantics at work here. When you say “virus”, are you using as narrowly technically defined, or as the broader general usage definition?

---

<div class="post-metadata">

**Author:** ![Czarcasm](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/czarcasm/32/4050_2.png) [@Czarcasm](https://boards.straightdope.com/u/Czarcasm)\
**Post date:** [June 28, 2018, 8:55pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/10 "2018-06-28T20:55:01Z")

</div>

> [@Sunny\_Daze](#):
>
> I can see why someone might ask this, but unless someone had programmed the code to behave in this manner, no, this could not happen.
> 
> ETA: there may be a question of semantics at work here. When you say “virus”, are you using as narrowly technically defined, or as the broader general usage definition?

What is the difference?

---

<div class="post-metadata">

**Author:** ![TSBG](https://avatars.discourse-cdn.com/v4/letter/t/77aa72/32.png) [@TSBG](https://boards.straightdope.com/u/TSBG)\
**Post date:** [June 28, 2018, 9:02pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/11 "2018-06-28T21:02:00Z")

</div>

I am no expert on this so sorry if this is impossibly stupid, but aren’t some “neural networks” capable of modifying their own code and generating new code? Could a computer virus arise as an unintended consequence?

---

<div class="post-metadata">

**Author:** ![Measure\_for\_Measure](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/measure_for_measure/32/557_2.png) [@Measure\_for\_Measure](https://boards.straightdope.com/u/Measure_for_Measure)\
**Post date:** [June 28, 2018, 9:02pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/12 "2018-06-28T21:02:20Z")

</div>

> [@Czarcasm](#):
>
> I’m not talking about a poorly written program that does what the writer didn’t intend it to do, but bits of random coding interacting to form computer virus.  
> I don’t know much about programming, so if this is a stupid question, let me know.

I don’t know what bits of random coding are. But worms have been released into the wild with unintended consequences. See [the Morris worm](https://en.wikipedia.org/wiki/Morris_worm).

---

<div class="post-metadata">

**Author:** ![Measure\_for\_Measure](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/measure_for_measure/32/557_2.png) [@Measure\_for\_Measure](https://boards.straightdope.com/u/Measure_for_Measure)\
**Post date:** [June 28, 2018, 9:03pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/13 "2018-06-28T21:03:43Z")

</div>

> [@Czarcasm](#):
>
> What is the difference?

The general term encompassing viruses, worms and other programmed nasties is malware.

> **[Malware](https://en.wikipedia.org/wiki/Malware)**
>
> Malware (a portmanteau for malicious software) is any software intentionally designed to cause disruption to a computer, server, client, or computer network, leak private information, gain unauthorized access to information or systems, deprive access to information, or which unknowingly interferes with the user's computer security and privacy. Researchers tend to classify malware into one or more sub-types (i.e. computer viruses, worms, Trojan horses, ransomware, spyware, adware Malware poses s...

---

<div class="post-metadata">

**Author:** ![Czarcasm](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/czarcasm/32/4050_2.png) [@Czarcasm](https://boards.straightdope.com/u/Czarcasm)\
**Post date:** [June 28, 2018, 9:05pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/14 "2018-06-28T21:05:44Z")

</div>

> [@Measure\_for\_Measure](#):
>
> The general term encompassing viruses, worms and other programmed nasties is malware.
> 
> [Malware - Wikipedia](https://en.wikipedia.org/wiki/Malware)

Malware is probably what I am asking about, then.

---

<div class="post-metadata">

**Author:** ![ftg](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ftg/32/2801_2.png) [@ftg](https://boards.straightdope.com/u/ftg)\
**Post date:** [June 28, 2018, 9:20pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/15 "2018-06-28T21:20:01Z")

</div>

One interesting example of a simple system with reproducing-like behavior is Conway’s Game of Life.

Early on, a “glider gun” was discovered by accident (not truly random). A pattern that repeatedly sent out “gliders” over and over. So a sort-of-randomish generation pattern was possible.

It took some time before truly self-replicating patterns were [found](https://en.wikipedia.org/wiki/Conway's_Game_of_Life#Self-replication), but not randomly at all.

OTOH, it wouldn’t take much for a _very_ large “universe” seeded with random patterns to come up with one of these and then you would have a virus (a.k.a. “life”\*).

Note that the simplicity of the rules of Life work in it’s favor. Regular computer code has much more complexity so randomly generating some code that does something interesting is much, much harder. Nevermind full self-replication.

- Conway’s naming implied such patterns presumably existed.

---

<div class="post-metadata">

**Author:** ![Voyager](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/voyager/32/133_2.png) [@Voyager](https://boards.straightdope.com/u/Voyager)\
**Post date:** [June 28, 2018, 9:53pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/16 "2018-06-28T21:53:14Z")

</div>

In 1959 a researcher from IBM did an experiment where he mutated machine language code to see if he could get a new working program. I think it was published in either the Spring Joint or Fall Joint Computing Conference (SJCC, FJCC). He ran lots of permutations, and I think he might have gotten one kind of program out of it, but it was nothing as complex as a piece of malware would be.

If you started with a working piece of malware you might accidentally produce another working piece of malware, but in general it is easier to be wrong than to be right. Didn’t some virus not activate because of a bug some time?  
So the answer is not bloody likely.

---

<div class="post-metadata">

**Author:** ![CharmaChameleon](https://avatars.discourse-cdn.com/v4/letter/c/9d8465/32.png) [@CharmaChameleon](https://boards.straightdope.com/u/CharmaChameleon)\
**Post date:** [June 28, 2018, 10:10pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/17 "2018-06-28T22:10:20Z")

</div>

In a former job a good part of my activity was devoted to scanning for malware signatures/patterns. This was on an Army contract, so the policy was enforced strictly, at least in our facility.

It was usually a good thing to find a known threat and not allow it to get onto our networks. However, the failure of “one size fits all” solutions became evident with one incident.

Our network consisted of VAX/VMS minicomputers, a large collection of different UNIX variants, Intel and AMD based PCs, and Macintoshes. But the only approved malware scanner only looked for malware aimed at Windows executables. More, every file to be imported (via diskette, tape, etc.) to any of our systems was required to pass the scanning software.

Now, one day a new release of production code came in. It was written to run in our IBM POWER6 systems using the IBM AIX operating system. The production code was written in C, C++, Ada, FORTRAN 90, PERL, and a whole lot of Bourne and Korn shell scripts. Guess what happened…

The scanner found a signature matching some malware. That malware **could only execute** in the Windows2000 operating environment **as malware**. That malware **could not execute** in the IBM AIX environment **as malware**. The production code had to be rejected for use in our facility.

(BTW, I do **not** fault the Army policy makers for this, as the standard was to ensure against any and all malware installations. The fact that the detected signature could not infect the AIX systems was in itself no guarantee that the code could not have been repackaged and then transmitted to a PC, where it might have been executed. I do fault the developers for ignoring their requirement to run the same scanner against their production code before it was delivered to the Army.)

I left the job shortly after that, and have no idea if the developers were able to overcome the (non-)difficulty.

---

<div class="post-metadata">

**Author:** ![Measure\_for\_Measure](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/measure_for_measure/32/557_2.png) [@Measure\_for\_Measure](https://boards.straightdope.com/u/Measure_for_Measure)\
**Post date:** [June 28, 2018, 10:22pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/18 "2018-06-28T22:22:06Z")

</div>

Unlike organic matter, random code doesn’t collide and combine all that much. To be sure random numbers are _generated_ all the time for simulation exercises. But those aren’t commands: they are data and interpreted as such. It isn’t hard to write a program that will create random code then attempt to execute it. But that’s not exactly a common (or rewarding) practice.  
But is code written that has unintended consequences? Sure: most programming time is devoted to debugging.

---

<div class="post-metadata">

**Author:** ![DPRK](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DPRK](https://boards.straightdope.com/u/DPRK)\
**Post date:** [June 28, 2018, 11:12pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/19 "2018-06-28T23:12:00Z")

</div>

> [@TSBG](#):
>
> I am no expert on this so sorry if this is impossibly stupid, but aren’t some “neural networks” capable of modifying their own code and generating new code? Could a computer virus arise as an unintended consequence?

No. Artificial neural networks are networks of artificial neurons, and have no “code” to modify. Neural networks are therefore less relevant to the subject of computer viruses than the traditional model of machine code executing on a von Neumann architecture.

In real life, viruses evolve as a result of biological mechanisms like selection pressure, mutation, recombination, etc. None of these apply to a computer operating system. A buggy computer program will often just crash, and the operating system is supposed to prevent it from being able to corrupt its own code or that of other programs. A piece of code that replicates itself by bypassing system permissions in order to infect other programs can only be the result of clever programming, not random bugs.

---

<div class="post-metadata">

**Author:** ![DPRK](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DPRK](https://boards.straightdope.com/u/DPRK)\
**Post date:** [June 28, 2018, 11:16pm UTC](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930/20 "2018-06-28T23:16:16Z")

</div>

> [@Measure\_for\_Measure](#):
>
> Unlike organic matter, random code doesn’t collide and combine all that much. To be sure random numbers are _generated_ all the time for simulation exercises. But those aren’t commands: they are data and interpreted as such. It isn’t hard to write a program that will create random code then attempt to execute it. But that’s not exactly a common (or rewarding) practice.

There is such a thing as evolutionary programming. Again, though, this is a deliberate type of programming via optimization, and is not suitable for developing computer malware, though if you know of such a thing it sounds quite revolutionary.

[Next page](https://boards.straightdope.com/t/can-computer-viruses-form-randomly-from-computer-code/816930.md?page=2)
