# Generate 20 lines of code where each line outputs either 1 or -1 randomly
import random
for _ in range(20):
print(random.choice([1, -1]))
// Generate 20 lines of either 1 or -1 randomly printed to console
for (let i = 0; i < 20; i++) {
console.log(Math.random() < 0.5 ? 1 : -1);
}
# Print 20 lines, each line either 1 or -1 randomly
20.times do
puts [-1, 1].sample
end
// Print 20 lines, each either 1 or -1 randomly
import java.util.Random;
public class OnesAndMinusOnes {
public static void main(String[] args) {
Random rand = new Random();
for (int i=0; i<20; i++) {
System.out.println(rand.nextBoolean() ? 1 : -1);
}
}
}
// Print 20 lines with either 1 or -1 randomly
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
srand(time(NULL));
for (int i = 0; i < 20; i++) {
printf("%d\n", rand() % 2 == 0 ? 1 : -1);
}
return 0;
}
# Print 20 lines of either 1 or -1 using bash
for i in {1..20}
do
if [ $((RANDOM % 2)) -eq 0 ]; then
echo 1
else
echo -1
fi
done
<?php
// Print 20 lines randomly 1 or -1
for ($i = 0; $i < 20; $i++) {
echo (rand(0, 1) ? 1 : -1) . PHP_EOL;
}
?>
// Print 20 lines of 1 or -1 randomly
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
rand.Seed(time.Now().UnixNano())
for i := 0; i < 20; i++ {
if rand.Intn(2) == 0 {
fmt.Println(1)
} else {
fmt.Println(-1)
}
}
}
// Print 20 lines of 1 or -1 randomly
using System;
class Program {
static void Main() {
Random rnd = new Random();
for (int i = 0; i < 20; i++) {
Console.WriteLine(rnd.Next(2) == 0 ? 1 : -1);
}
}
}
// Print 20 lines, each line either 1 or -1 randomly
import Foundation
for _ in 1...20 {
print(Bool.random() ? 1 : -1)
}
// Print 20 lines, each either 1 or -1 randomly
fun main() {
val rnd = java.util.Random()
repeat(20) {
println(if (rnd.nextBoolean()) 1 else -1)
}
}
# Print 20 lines either 1 or -1 randomly
set.seed(Sys.time())
for (i in 1:20) {
print(sample(c(-1,1), 1))
}
// Print 20 lines of 1 or -1 randomly
import scala.util.Random
object Main extends App {
val rnd = new Random()
for (_ <- 1 to 20) {
println(if (rnd.nextBoolean()) 1 else -1)
}
}
# Print 20 lines of either 1 or -1 randomly
use strict;
use warnings;
for (1..20) {
print ((rand() < 0.5) ? "1\n" : "-1\n");
}
// Print 20 lines of 1 or -1 randomly
for (let i = 0; i < 20; i++) {
console.log(Math.random() < 0.5 ? 1 : -1);
}
// Print 20 lines either 1 or -1 randomly
import 'dart:math';
void main() {
var rnd = Random();
for (var i = 0; i < 20; i++) {
print(rnd.nextBool() ? 1 : -1);
}
}
-- Print 20 lines of 1 or -1 randomly
math.randomseed(os.time())
for i=1,20 do
if math.random(0,1) == 0 then
print(1)
else
print(-1)
end
end
-- Print 20 lines of 1 or -1 randomly
import System.Random
main :: IO ()
main = do
gen <- getStdGen
let bools = take 20 (randoms gen :: [Bool])
mapM_ (putStrLn . (\b -> if b then "1" else "-1")) bools
% Print 20 lines of 1 or -1 randomly
rng('shuffle');
for i=1:20
if rand() < 0.5
disp(1)
else
disp(-1)
end
end
# Print 20 lines of 1 or -1 randomly
for ($i=0; $i -lt 20; $i++) {
if (Get-Random -Maximum 2) {
Write-Output 1
} else {
Write-Output -1
}
}