class String
def random_caps
letters = self.split("")
letters.length.times do |n|
letters[n] = letters[n].upcase if rand(4) == 0
end
letters.join("")
end
end
created after total boredom.
discuss uses, etc.
Name:
Anonymous2007-08-13 3:31 ID:y0hQ6b0E
from random import*;random_caps=lambda s:''.join(chr(ord(c)^((random()>0.75)*32))for c in s)
Name:
Anonymous2007-08-13 3:44 ID:HTcG9yxK
;RANDOM_CAPS
;THIS ROUTINE REQUIRES 2 2-BYTE POINTERS IN ZERO PAGE
; IDENTIFYING WHERE THE INPUT AND OUTPUT STRINGS ARE
;SELECT APPROPRIATE LOCATIONS FOR YOUR SYSTEM
;THE FOLLOWING WORKS ON COMMODORE 64 ARCHITECTURE
INPUT EQU 251
OUTPUT EQU 253
;STRINGS MUST BE TERMINATED WITH A ZERO BYTE AND BE LESS
; THAN 255 CHARACTERS IN LENGTH
;THIS ROUTINE ALSO REQUIRES ANOTHER ROUTINE NAMED 'RANDOM'
; THAT PRODUCES A RANDOM OR PSEUDORANDOM NUMBER IN .A
; YOU HAVE TO WRITE THAT ONE YOUR DAMN SELF
RNDCAP LDY #0 ;START AT 0
LOOP LDA (INPUT),Y ;GET A CHAR
BEQ DONE ;IF ZERO, STOP
TAX ;SAVE IN X
JSR RANDOM ;GET RANDOM
CMP 64 ;64 FOR 1 IN 4 CHANCE
BCS SKIP ;IF MORE THAN 64 SKIP IT
TXA ;GET BACK A
AND #%11011111 ;TURN OFF BIT 6, MAEK IT CAPITAL
JMP CONT ;NXT PLZ
SKIP TXA
STA (OUTPUT),Y ;STORE THE SHIT
CONT INY ;SO, NXT PLZ
BEQ DONE; BUT IF .Y = 0 IT FLIPPED OVER, QUIT
JMP LOOP; LOOP
DONE RTS
;STUB ROUTINE, MAKE YOUR OWN
RANDOM LDA #255
RTS
>>1
Pass all your email through it. Other useful filters, implementation not shown:
>>>print leetify("I want that report done by friday! No more slacking off. -- Boss.")
Omglol! i want t4at report done by fridaY!!!!11 no more slackiNg off. -- bsz
>>>print smurfify("Why do you never answer my email? If this continues I will have to fire you!")
Why do smurf never smurf my smurf? Smurf this continues I smurf have to smurf smurf!
>>22
for a fair comparison, it should look something like this (and the function is called rand()):
void random_caps(char* s)
{
for(;*s=(rand()%2?toupper:tolower)(*s);s++);
}
or if you want to compete with the one liners:
void random_caps(char* s){for(;*s=(rand()%2?toupper:tolower)(*s);s++);}