File size: 943 Bytes
1e03943
2206726
1e03943
 
 
 
 
 
 
 
 
 
 
2206726
1e03943
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import random

def simulate_channel(text: str, error_rate: float = 0.15) -> str:
    """
    Simulates a noisy 6G wireless channel.
    It randomly destroys characters based on the error_rate probability.
    """
    if not text:
        return ""
        
    corrupted_message = []
    # These are the 'static' symbols that replace your text when the signal drops
    noise_symbols = "!@#$%^&*~?"
    
    for char in text:
        # Use probability to decide if this specific character survives the transmission
        if random.random() < error_rate and char != " ":
            # The signal dropped! Replace the letter with a random noise symbol
            corrupted_message.append(random.choice(noise_symbols))
        else:
            # The signal survived! Keep the original letter
            corrupted_message.append(char)
            
    # Join the pieces back together into a single string
    return "".join(corrupted_message)