diff options
author | xultist <xultist@proton.me> | 2023-02-25 21:31:16 +1100 |
---|---|---|
committer | xultist <xultist@proton.me> | 2023-02-25 21:31:16 +1100 |
commit | 328595786b6ac60de6249b9d6035e5ef381faf6b (patch) | |
tree | a7c2b677c5e2569f6c5e0775b8354fe04114ac8e | |
parent | 5426ee6fabe2ec650412940d3a7eabe834fcdce8 (diff) |
-rw-r--r-- | src/Ada.adb | 31 | ||||
-rw-r--r-- | src/Bash.bash | 5 | ||||
-rw-r--r-- | src/C++.cpp | 35 | ||||
-rw-r--r-- | src/CLang.c | 36 | ||||
-rw-r--r-- | src/COBOL.cbl | 33 | ||||
-rw-r--r-- | src/CS.cs | 41 | ||||
-rw-r--r-- | src/DLang.d | 11 | ||||
-rw-r--r-- | src/Dart.dart | 13 | ||||
-rw-r--r-- | src/Fortran.f90 | 26 | ||||
-rw-r--r-- | src/Golang.go | 38 | ||||
-rw-r--r-- | src/HTML.html | 21 | ||||
-rw-r--r-- | src/Haskell.hs | 9 | ||||
-rw-r--r-- | src/Java.java | 33 | ||||
-rw-r--r-- | src/JavaScript.JS | 22 | ||||
-rw-r--r-- | src/Julia.jl | 9 | ||||
-rw-r--r-- | src/Kotlin.kt | 10 | ||||
-rw-r--r-- | src/Lisp.lisp | 12 | ||||
-rw-r--r-- | src/Lua.lua | 22 | ||||
-rw-r--r-- | src/MATLAB.M | 12 | ||||
-rw-r--r-- | src/ObjectiveC.m | 29 | ||||
-rw-r--r-- | src/PHP.php | 14 | ||||
-rw-r--r-- | src/Pascal.dpr | 33 | ||||
-rw-r--r-- | src/Perl.pl | 14 | ||||
-rw-r--r-- | src/Powershell.ps1 | 3 | ||||
-rw-r--r-- | src/Prolog.pl | 34 | ||||
-rw-r--r-- | src/Python.py | 12 | ||||
-rw-r--r-- | src/R.r | 12 | ||||
-rw-r--r-- | src/Ruby.rb | 10 | ||||
-rw-r--r-- | src/Rust.rs | 14 | ||||
-rw-r--r-- | src/Scala.scala | 8 | ||||
-rw-r--r-- | src/Swift.swift | 16 | ||||
-rw-r--r-- | src/VisualBasicNET.vb | 34 | ||||
-rwxr-xr-x | src/bash.sh | 1 | ||||
-rw-r--r-- | src/c.c | 32 | ||||
-rw-r--r-- | src/cplusplus.cpp | 29 | ||||
-rw-r--r-- | src/dart.dart | 11 | ||||
-rw-r--r-- | src/go.go | 38 | ||||
-rw-r--r-- | src/java.java | 20 | ||||
-rw-r--r-- | src/julia.jl | 7 | ||||
-rw-r--r-- | src/kotlin.kt | 7 | ||||
-rw-r--r-- | src/php.php | 7 | ||||
-rw-r--r-- | src/powershell.ps1 | 2 | ||||
-rw-r--r-- | src/python.py | 6 | ||||
-rw-r--r-- | src/r.r | 5 | ||||
-rw-r--r-- | src/ruby.rb | 2 | ||||
-rw-r--r-- | src/rust.rs | 11 | ||||
-rw-r--r-- | src/scala.scala | 7 | ||||
-rw-r--r-- | src/swift.swift | 13 | ||||
-rw-r--r-- | src/x86ASM.asm | 89 | ||||
-rw-r--r-- | wordLists/happy.txt | 712 | ||||
-rw-r--r-- | wordLists/vocab.txt (renamed from src/vocab.txt) | 2 |
51 files changed, 1454 insertions, 199 deletions
diff --git a/src/Ada.adb b/src/Ada.adb new file mode 100644 index 0000000..7afca84 --- /dev/null +++ b/src/Ada.adb @@ -0,0 +1,31 @@ +with Ada.Text_IO; use Ada.Text_IO; +with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; +with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; + +procedure Random_Words is + Num_Words : Natural := 30; + Word_List : array (1 .. Num_Words) of Unbounded_String; + Vocab_File : File_Type; +begin + Ada.Text_IO.Open (File => Vocab_File, Mode => Ada.Text_IO.In_File, + Name => "wordLists/vocab.txt"); + for I in 1 .. Num_Words loop + declare + Line : Unbounded_String; + begin + Ada.Text_IO.Get_Line (File => Vocab_File, Item => Line); + Word_List (I) := Line (1 .. Line'Length); + exception + when Ada.Text_IO.End_Error => + Num_Words := I - 1; + exit; + end; + end loop; + Ada.Text_IO.Close (File => Vocab_File); + for I in 1 .. Num_Words loop + Ada.Text_IO.Put (Word_List (I)); + if I < Num_Words then + Ada.Text_IO.Put (" "); + end if; + end loop; +end Random_Words; diff --git a/src/Bash.bash b/src/Bash.bash new file mode 100644 index 0000000..7b71919 --- /dev/null +++ b/src/Bash.bash @@ -0,0 +1,5 @@ +#!/bin/bash + +words=($(cat ../wordLists/vocab.txt)) +sample=($(echo "${words[@]}" | tr ' ' '\n' | shuf -n 30)) +echo "${sample[*]}" diff --git a/src/C++.cpp b/src/C++.cpp new file mode 100644 index 0000000..01e7a96 --- /dev/null +++ b/src/C++.cpp @@ -0,0 +1,35 @@ +#include <iostream> +#include <fstream> +#include <string> +#include <vector> +#include <random> +#include <algorithm> + +int main() { + std::vector<std::string> words; + std::string word; + std::ifstream file("../wordLists/vocab.txt"); + + while (std::getline(file, word)) { + words.push_back(word); + } + + std::mt19937 rng(std::random_device{}()); + std::uniform_int_distribution<int> dist(0, words.size() - 1); + + const int NUM_WORDS = 30; + std::vector<std::string> selected_words; + while (selected_words.size() < NUM_WORDS) { + int index = dist(rng); + if (std::find(selected_words.begin(), selected_words.end(), words[index]) == selected_words.end()) { + selected_words.push_back(words[index]); + } + } + + for (int i = 0; i < NUM_WORDS; i++) { + std::cout << selected_words[i] << " "; + } + std::cout << std::endl; + + return 0; +}
\ No newline at end of file diff --git a/src/CLang.c b/src/CLang.c new file mode 100644 index 0000000..99380ab --- /dev/null +++ b/src/CLang.c @@ -0,0 +1,36 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +#define MAX_WORDS 1000 +#define NUM_WORDS 30 + +int main() { + char words[MAX_WORDS][100]; + char output_str[3000] = ""; + int num_words = 0, i; + FILE *file = fopen("../wordLists/vocab.txt", "r"); + + while (fgets(words[num_words], 100, file)) { + num_words++; + if (num_words == MAX_WORDS) { + break; + } + } + + srand(time(NULL)); + + for (i = 0; i < NUM_WORDS; i++) { + int index = rand() % num_words; + strcat(output_str, words[index]); + if (i < NUM_WORDS - 1) { + strcat(output_str, ""); + } + } + + printf("%s\n", output_str); + + fclose(file); + return 0; +}
\ No newline at end of file diff --git a/src/COBOL.cbl b/src/COBOL.cbl new file mode 100644 index 0000000..b541b19 --- /dev/null +++ b/src/COBOL.cbl @@ -0,0 +1,33 @@ +IDENTIFICATION DIVISION. +PROGRAM-ID. RANDOM-WORDS. +ENVIRONMENT DIVISION. +INPUT-OUTPUT SECTION. +FILE-CONTROL. + SELECT VOCAB-FILE ASSIGN TO "wordLists/vocab.txt". +DATA DIVISION. +FILE SECTION. +FD VOCAB-FILE. +01 VOCAB-REC PIC X(20). +WORKING-STORAGE SECTION. +01 WORD-TABLE. + 05 WORD-LIST OCCURS 30 TIMES PIC X(20). +01 NUM-WORDS PIC 99 VALUE 30. +01 I PIC 99. +PROCEDURE DIVISION. +OPEN-FILES. + OPEN INPUT VOCAB-FILE. +GENERATE-WORDS. + PERFORM VARYING I FROM 1 BY 1 UNTIL I > NUM-WORDS + READ VOCAB-FILE INTO VOCAB-REC + MOVE VOCAB-REC TO WORD-LIST(I) + END-PERFORM. +DISPLAY-WORDS. + PERFORM VARYING I FROM 1 BY 1 UNTIL I > NUM-WORDS + DISPLAY WORD-LIST(I) + IF I < NUM-WORDS + DISPLAY " " + END-IF + END-PERFORM. +CLOSE-FILES. + CLOSE VOCAB-FILE. +STOP-RUN. diff --git a/src/CS.cs b/src/CS.cs new file mode 100644 index 0000000..99970ea --- /dev/null +++ b/src/CS.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +class GodSpeak +{ + static void Main() + { + string fileName = "../wordLists/vocab.txt"; + List<string> words = new List<string>(); + try + { + using (StreamReader reader = new StreamReader(fileName)) + { + string line; + while ((line = reader.ReadLine()) != null) + { + words.Add(line); + } + } + } + catch (IOException e) + { + Console.WriteLine("Error reading file: {0}", e.Message); + return; + } + Random random = new Random(); + List<string> chosenWords = new List<string>(); + while (chosenWords.Count < 30) + { + int index = random.Next(words.Count); + string word = words[index]; + if (!chosenWords.Contains(word)) + { + chosenWords.Add(word); + } + } + Console.WriteLine(string.Join(" ", chosenWords)); + } +} diff --git a/src/DLang.d b/src/DLang.d new file mode 100644 index 0000000..d5ed889 --- /dev/null +++ b/src/DLang.d @@ -0,0 +1,11 @@ +import std.stdio; +import std.file : readText; +import std.algorithm : randomSample; + +void main() +{ + auto contents = readText("../wordLists/vocab.txt"); + auto words = contents.split("\n"); + auto sample = words.randomSample(30); + writeln(sample.join(" ")); +} diff --git a/src/Dart.dart b/src/Dart.dart new file mode 100644 index 0000000..ebe15fd --- /dev/null +++ b/src/Dart.dart @@ -0,0 +1,13 @@ +import 'dart:io'; +import 'dart:math'; + +void main() { + var words = File('wordLists/vocab.txt').readAsLinesSync(); + var numWords = min(words.length, 30); + var indices = Set<int>(); + while (indices.length < numWords) { + indices.add(Random().nextInt(words.length)); + } + var wordList = indices.map((i) => words[i]).toList(); + print(wordList.join(' ')); +}
\ No newline at end of file diff --git a/src/Fortran.f90 b/src/Fortran.f90 new file mode 100644 index 0000000..e8fbbbe --- /dev/null +++ b/src/Fortran.f90 @@ -0,0 +1,26 @@ +program random_words + use, intrinsic :: iso_fortran_env + implicit none + + integer :: i, n, random_indices(30) + character(len=:), allocatable :: words(:), selected_words(30) + + open(unit=10, file="../wordLists/vocab.txt", status='old', action='read') + n = 0 + do while (.not. eof(10)) + read(10, '(a)', iostat=i) selected_words(n+1) + if (i == 0) then + n = n + 1 + allocate(words(n)) + words(n) = selected_words(n) + end if + end do + close(10) + + call random_seed() + call random_number(random_indices) + random_indices = floor(random_indices * n) + 1 + selected_words = words(random_indices) + + write(*, '(a)') join(selected_words, ' ') +end program random_words diff --git a/src/Golang.go b/src/Golang.go new file mode 100644 index 0000000..f5647f2 --- /dev/null +++ b/src/Golang.go @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "io/ioutil" + "math/rand" + "strings" + "time" +) + +func main() { + filepath := "../wordLists/vocab.txt" + content, err := ioutil.ReadFile(filepath) + if err != nil { + panic(err) + } + words := strings.Split(string(content), "\n") + numWords := len(words) + rand.Seed(time.Now().UnixNano()) + chosenWords := make([]string, 0, 30) + for len(chosenWords) < 30 { + randNum := rand.Intn(numWords) + word := words[randNum] + if !contains(chosenWords, word) { + chosenWords = append(chosenWords, word) + } + } + fmt.Println(strings.Join(chosenWords, " ")) +} + +func contains(words []string, word string) bool { + for _, w := range words { + if w == word { + return true + } + } + return false +} diff --git a/src/HTML.html b/src/HTML.html new file mode 100644 index 0000000..95ec3aa --- /dev/null +++ b/src/HTML.html @@ -0,0 +1,21 @@ +<!DOCTYPE html> +<html> +<head> + <title>Random Word Sample</title> +</head> +<body> + <button onclick="generateSample()">Generate Sample</button> + <p id="sample"></p> + <script> + function generateSample() { + fetch('../wordLists/vocab.txt') + .then(response => response.text()) + .then(text => { + let words = text.trim().split('\n'); + let sample = words.sort(() => Math.random() - 0.5).slice(0, 30); + document.getElementById('sample').textContent = sample.join(' '); + }); + } + </script> +</body> +</html> diff --git a/src/Haskell.hs b/src/Haskell.hs new file mode 100644 index 0000000..b028a85 --- /dev/null +++ b/src/Haskell.hs @@ -0,0 +1,9 @@ +import System.Random (randomRs, newStdGen) + +main :: IO () +main = do + contents <- readFile "../wordLists/vocab.txt" + let words = lines contents + gen <- newStdGen + let sample = take 30 $ randomRs (0, length words - 1) gen + putStrLn $ unwords $ map (words !!) sample
\ No newline at end of file diff --git a/src/Java.java b/src/Java.java new file mode 100644 index 0000000..4fe2675 --- /dev/null +++ b/src/Java.java @@ -0,0 +1,33 @@ +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Random; + +class GodSpeak { + public static void main(String[] args) { + String fileName = "../wordLists/vocab.txt"; + ArrayList<String> words = new ArrayList<>(); + try { + BufferedReader reader = new BufferedReader(new FileReader(fileName)); + String line; + while ((line = reader.readLine()) != null) { + words.add(line); + } + reader.close(); + } catch (IOException e) { + System.err.println("Error reading file: " + e.getMessage()); + System.exit(1); + } + Random random = new Random(); + ArrayList<String> chosenWords = new ArrayList<>(); + while (chosenWords.size() < 30) { + int index = random.nextInt(words.size()); + String word = words.get(index); + if (!chosenWords.contains(word)) { + chosenWords.add(word); + } + } + System.out.println(String.join(" ", chosenWords)); + } +}
\ No newline at end of file diff --git a/src/JavaScript.JS b/src/JavaScript.JS new file mode 100644 index 0000000..41834f6 --- /dev/null +++ b/src/JavaScript.JS @@ -0,0 +1,22 @@ +const fs = require('fs'); + +fs.readFile('../wordLists/vocab.txt', 'utf8', (err, data) => { + if (err) { + console.error(`Error reading file: ${err}`); + return; + } + + const words = data.trim().split('\n'); + const chosenWords = []; + + while (chosenWords.length < 30) { + const randomIndex = Math.floor(Math.random() * words.length); + const word = words[randomIndex].trim(); + + if (!chosenWords.includes(word)) { + chosenWords.push(word); + } + } + + console.log(chosenWords.join(' ')); +});
\ No newline at end of file diff --git a/src/Julia.jl b/src/Julia.jl new file mode 100644 index 0000000..9082d1c --- /dev/null +++ b/src/Julia.jl @@ -0,0 +1,9 @@ +using Random + +function main() + words = readlines("../wordLists/vocab.txt") + selected_words = sample(words, 30, replace=false) + println(join(selected_words, " ")) +end + +main()
\ No newline at end of file diff --git a/src/Kotlin.kt b/src/Kotlin.kt new file mode 100644 index 0000000..0046a71 --- /dev/null +++ b/src/Kotlin.kt @@ -0,0 +1,10 @@ +import java.io.File +import kotlin.random.Random + +fun main() { + val words = File("../wordLists/vocab.txt").readLines() + + val selectedWords = words.shuffled(Random).take(30) + + println(selectedWords.joinToString(" ")) +}
\ No newline at end of file diff --git a/src/Lisp.lisp b/src/Lisp.lisp new file mode 100644 index 0000000..bb23851 --- /dev/null +++ b/src/Lisp.lisp @@ -0,0 +1,12 @@ +(defun pick-random-words (num-words) + (with-open-file (vocab-file "wordLists/vocab.txt") + (let* ((words (loop for line = (read-line vocab-file nil) + while line collect line)) + (num-words (min num-words (length words))) + (indices (remove-duplicates (loop repeat num-words + collect (random (length words)))))) + (loop for i in indices + collect (nth i words))))) + + +(format t "~{~a~^ ~}" (pick-random-words 30))
\ No newline at end of file diff --git a/src/Lua.lua b/src/Lua.lua new file mode 100644 index 0000000..823d408 --- /dev/null +++ b/src/Lua.lua @@ -0,0 +1,22 @@ +math.randomseed(os.time()) + +function main() + local file = io.open("../wordLists/vocab.txt", "r") + local words = {} + for line in file:lines() do + table.insert(words, line) + end + file:close() + + local selected_words = {} + while #selected_words < 30 do + local word = words[math.random(#words)] + if not selected_words[word] then + table.insert(selected_words, word) + end + end + + print(table.concat(selected_words, " ")) +end + +main() diff --git a/src/MATLAB.M b/src/MATLAB.M new file mode 100644 index 0000000..dd2cdaa --- /dev/null +++ b/src/MATLAB.M @@ -0,0 +1,12 @@ +filepath = '../wordLists/vocab.txt'; +words = importdata(filepath); +numWords = length(words); +chosenWords = {}; +while length(chosenWords) < 30 + randNum = randi(numWords); + word = words{randNum}; + if ~any(strcmp(chosenWords, word)) + chosenWords = [chosenWords, word]; + end +end +disp(strjoin(chosenWords, ' ')); diff --git a/src/ObjectiveC.m b/src/ObjectiveC.m new file mode 100644 index 0000000..e9bd566 --- /dev/null +++ b/src/ObjectiveC.m @@ -0,0 +1,29 @@ +#import <Foundation/Foundation.h> + +int main(int argc, const char * argv[]) { + @autoreleasepool { + NSError *error = nil; + NSString *filePath = @"../wordLists/vocab.txt"; + NSString *fileContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error]; + + if (error != nil) { + NSLog(@"Error reading file: %@", [error localizedDescription]); + return 1; + } + + NSArray *words = [fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]; + words = [words filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self != ''"]]; + + NSMutableArray *chosenWords = [[NSMutableArray alloc] init]; + + while ([chosenWords count] < 30) { + NSInteger i = arc4random_uniform((uint32_t)[words count]); + [chosenWords addObject:[words objectAtIndex:i]]; + [words removeObjectAtIndex:i]; + } + + NSString *output = [chosenWords componentsJoinedByString:@" "]; + NSLog(@"%@", output); + } + return 0; +}
\ No newline at end of file diff --git a/src/PHP.php b/src/PHP.php new file mode 100644 index 0000000..2cc1558 --- /dev/null +++ b/src/PHP.php @@ -0,0 +1,14 @@ +<?php +$filepath = "../wordLists/vocab.txt"; +$words = file($filepath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); +$chosen_words = array(); +$num_words = count($words); +while (count($chosen_words) < 30) { + $rand_num = rand(0, $num_words - 1); + $word = $words[$rand_num]; + if (!in_array($word, $chosen_words)) { + $chosen_words[] = $word; + } +} +echo implode(' ', $chosen_words); +?> diff --git a/src/Pascal.dpr b/src/Pascal.dpr new file mode 100644 index 0000000..daa2ffc --- /dev/null +++ b/src/Pascal.dpr @@ -0,0 +1,33 @@ +program randomWords; + +{$APPTYPE CONSOLE} + +uses + SysUtils, StrUtils, Classes; + +var + words: TStrings; + i, numWords: integer; + chosenWords: TStringList; +begin + Randomize; + words := TStringList.Create; + try + words.LoadFromFile('../wordLists/vocab.txt'); + numWords := words.Count; + chosenWords := TStringList.Create; + try + while chosenWords.Count < 30 do + begin + i := Random(numWords); + if chosenWords.IndexOf(words[i]) = -1 then + chosenWords.Add(words[i]); + end; + WriteLn(chosenWords.DelimitedText); + finally + chosenWords.Free; + end; + finally + words.Free; + end; +end. diff --git a/src/Perl.pl b/src/Perl.pl new file mode 100644 index 0000000..b00b5f9 --- /dev/null +++ b/src/Perl.pl @@ -0,0 +1,14 @@ +open my $fh, '<', '../wordLists/vocab.txt' or die "Couldn't open file: $!"; +my @words = <$fh>; +close $fh; + +chomp @words; + +my @chosen_words; + +while (@chosen_words < 30) { + my $i = int(rand(scalar(@words))); + push @chosen_words, splice(@words, $i, 1); +} + +print join(" ", @chosen_words), "\n";
\ No newline at end of file diff --git a/src/Powershell.ps1 b/src/Powershell.ps1 new file mode 100644 index 0000000..4685097 --- /dev/null +++ b/src/Powershell.ps1 @@ -0,0 +1,3 @@ +$words = Get-Content ../wordLists/vocab.txt +$sample = $words | Get-Random -Count 30 +$sample -join ' '
\ No newline at end of file diff --git a/src/Prolog.pl b/src/Prolog.pl new file mode 100644 index 0000000..df3586b --- /dev/null +++ b/src/Prolog.pl @@ -0,0 +1,34 @@ +:- use_module(library(random)). +:- initialization main. + +main :- + read_file("../wordLists/vocab.txt", Words), + random_sample(Words, 30, Sample), + atomic_list_concat(Sample, ' ', SampleStr), + write(SampleStr). + +read_file(Path, Lines) :- + open(Path, read, Stream), + read_lines(Stream, Lines), + close(Stream). + +read_lines(Stream, []) :- + at_end_of_stream(Stream). +read_lines(Stream, [Line|Lines]) :- + \+ at_end_of_stream(Stream), + read_line_to_string(Stream, Line), + read_lines(Stream, Lines). + +random_sample(List, N, Sample) :- + length(List, Len), + ( Len =< N -> + Sample = List + ; random_permutation(List, Shuffled), + first_n(Shuffled, N, Sample) + ). + +first_n(_, 0, []). +first_n([H|T], N, [H|Sample]) :- + N > 0, + NextN is N - 1, + first_n(T, NextN, Sample).
\ No newline at end of file diff --git a/src/Python.py b/src/Python.py new file mode 100644 index 0000000..66a72fe --- /dev/null +++ b/src/Python.py @@ -0,0 +1,12 @@ +import random + +with open('../wordLists/vocab.txt', 'r') as f: + words = f.read().splitlines() + +selected_words = random.sample(words, 30) + +output_str = "" +for word in selected_words: + output_str += word + " " + +print(output_str) @@ -0,0 +1,12 @@ +filepath <- "../wordLists/vocab.txt" +words <- readLines(filepath) +chosen_words <- character(0) +num_words <- length(words) +while (length(chosen_words) < 30) { + rand_num <- sample(1:num_words, 1) + word <- words[rand_num] + if (!(word %in% chosen_words)) { + chosen_words <- c(chosen_words, word) + } +} +cat(paste(chosen_words, collapse = " "))
\ No newline at end of file diff --git a/src/Ruby.rb b/src/Ruby.rb new file mode 100644 index 0000000..1e054eb --- /dev/null +++ b/src/Ruby.rb @@ -0,0 +1,10 @@ + +words = File.readlines('../wordLists/vocab.txt').map(&:chomp) +chosen_words = [] + +while chosen_words.length < 30 + i = rand(words.length) + chosen_words << words.delete_at(i) +end + +puts chosen_words.join(' ')
\ No newline at end of file diff --git a/src/Rust.rs b/src/Rust.rs new file mode 100644 index 0000000..16d43bc --- /dev/null +++ b/src/Rust.rs @@ -0,0 +1,14 @@ +use rand::seq::SliceRandom; +use std::fs; + +fn main() { + let content = fs::read_to_string("../wordLists/vocab.txt") + .expect("Could not read file"); + + let words: Vec<&str> = content.split('\n').collect(); + + let mut rng = rand::thread_rng(); + let selected_words: Vec<&str> = words.choose_multiple(&mut rng, 30).collect(); + + println!("{}", selected_words.join(" ")); +}
\ No newline at end of file diff --git a/src/Scala.scala b/src/Scala.scala new file mode 100644 index 0000000..42e6b6f --- /dev/null +++ b/src/Scala.scala @@ -0,0 +1,8 @@ +import scala.io.Source +import scala.util.Random + +val words = Source.fromFile("wordLists/vocab.txt").getLines.toList +val numWords = math.min(words.length, 30) +val indices = Random.shuffle(words.indices.toList).take(numWords) +val wordList = indices.map(words).mkString(" ") +println(wordList) diff --git a/src/Swift.swift b/src/Swift.swift new file mode 100644 index 0000000..da7e35f --- /dev/null +++ b/src/Swift.swift @@ -0,0 +1,16 @@ +import Foundation + +let filepath = "../wordLists/vocab.txt" +let contents = try String(contentsOfFile: filepath, encoding: .utf8) +let words = contents.components(separatedBy: .newlines) +let numWords = words.count +var chosenWords = [String]() +while chosenWords.count < 30 { + let randNum = Int.random(in: 0..<numWords) + let word = words[randNum] + if !chosenWords.contains(word) { + chosenWords.append(word) + } +} +let output = chosenWords.joined(separator: " ") +print(output)
\ No newline at end of file diff --git a/src/VisualBasicNET.vb b/src/VisualBasicNET.vb new file mode 100644 index 0000000..a210386 --- /dev/null +++ b/src/VisualBasicNET.vb @@ -0,0 +1,34 @@ +Imports System.IO +Imports System.Linq + +Module GodWords + + Sub Main() + Dim fileName As String = "../wordLists/vocab.txt" + Dim words As New List(Of String) + Try + Using reader As New StreamReader(fileName) + Dim line As String + While (line = reader.ReadLine()) IsNot Nothing + words.Add(line) + End While + End Using + Catch ex As IOException + Console.WriteLine("Error reading file: {0}", ex.Message) + Return + End Try + + Dim random As New Random() + Dim chosenWords As New List(Of String) + While chosenWords.Count < 30 + Dim index As Integer = random.Next(words.Count) + Dim word As String = words(index) + If Not chosenWords.Contains(word) Then + chosenWords.Add(word) + End If + End While + + Console.WriteLine(String.Join(" ", chosenWords)) + End Sub + +End Module diff --git a/src/bash.sh b/src/bash.sh deleted file mode 100755 index dadab3f..0000000 --- a/src/bash.sh +++ /dev/null @@ -1 +0,0 @@ -shuf -n 1 vocab.txt diff --git a/src/c.c b/src/c.c deleted file mode 100644 index 5113312..0000000 --- a/src/c.c +++ /dev/null @@ -1,32 +0,0 @@ -// https://cplusplus.com/forum/beginner/274150/ -// https://cplusplus.com/user/seeplus/ - -#include <stdlib.h> -#include <stdio.h> -#include <time.h> -#include <string.h> - -#define LSIZE 128 -#define RSIZE 50 -#define MAX 1000 - -int main() -{ - const char fname[MAX] = "vocab.txt"; - FILE* file = fopen(fname, "r"); - - if (file == NULL) { - puts("Cannot open file"); - return 1; - } - - char line[LSIZE][RSIZE]; - int tot = 0; - - srand(time(NULL)); - - for (; tot < LSIZE && fscanf(file, "%*d ")!= EOF && fgets(line[tot], RSIZE, file); ++tot) - line[tot][strlen(line[tot]) - 1] = '\0'; - - printf("%s\n", line[rand() % tot]); -} diff --git a/src/cplusplus.cpp b/src/cplusplus.cpp deleted file mode 100644 index 9954019..0000000 --- a/src/cplusplus.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// https://www.codespeedy.com/fetch-a-random-line-from-a-text-file-in-cpp/ - -#include <fstream> -#include <iostream> -#include <stdlib.h> -#include <time.h> -#include <vector> -using namespace std; - -int main() { - string line; - vector<string> lines; - - srand(time(0)); - - ifstream file("vocab.txt"); - - int total_lines = 0; - while (getline(file, line)) { - total_lines++; - lines.push_back(line); - } - - int random_number = rand() % total_lines; - - cout << lines[random_number]; - - return 0; -} diff --git a/src/dart.dart b/src/dart.dart deleted file mode 100644 index ba6505d..0000000 --- a/src/dart.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'dart:io'; -import 'dart:math'; - -void main() { - var file = new File('vocab.txt'); - file.readAsLines().then((List<String> lines) { - var random = new Random(); - var randomLine = lines[random.nextInt(lines.length)]; - print(randomLine); - }); -} diff --git a/src/go.go b/src/go.go deleted file mode 100644 index aef7926..0000000 --- a/src/go.go +++ /dev/null @@ -1,38 +0,0 @@ -package main - -import ( - "bufio" - "fmt" - "math/rand" - "os" - "time" -) - -func randomLine(fileName string) string { - rand.Seed(time.Now().UnixNano()) - lines, err := readLines(fileName) - if err != nil { - fmt.Println("Error reading file:", err) - os.Exit(1) - } - return lines[rand.Intn(len(lines))] -} - -func readLines(fileName string) ([]string, error) { - file, err := os.Open(fileName) - if err != nil { - return nil, err - } - defer file.Close() - - var lines []string - scanner := bufio.NewScanner(file) - for scanner.Scan() { - lines = append(lines, scanner.Text()) - } - return lines, scanner.Err() -} - -func main() { - fmt.Println(randomLine("vocab.txt")) -} diff --git a/src/java.java b/src/java.java deleted file mode 100644 index dfd29f8..0000000 --- a/src/java.java +++ /dev/null @@ -1,20 +0,0 @@ -// https://stackoverflow.com/a/30465683 - -import java.io.*; -import java.util.*; - -class Main { - public static void main(String[] args) throws FileNotFoundException, IOException { - FileInputStream fs = new FileInputStream("vocab.txt"); - BufferedReader br = new BufferedReader(new InputStreamReader(fs)); - ArrayList<String> array = new ArrayList<>(); - String line; - while ((line = br.readLine()) != null) - array.add(line); - - Random rand = new Random(); - int randomIndex = rand.nextInt(array.size()); - - System.out.println(array.get(randomIndex)); - } -}
\ No newline at end of file diff --git a/src/julia.jl b/src/julia.jl deleted file mode 100644 index 6f0b104..0000000 --- a/src/julia.jl +++ /dev/null @@ -1,7 +0,0 @@ -using StatsBase - -open("vocab.txt", "r") do f - godspeak = sample(readlines(f)) - println(godspeak) -end - diff --git a/src/kotlin.kt b/src/kotlin.kt deleted file mode 100644 index 5f1a34b..0000000 --- a/src/kotlin.kt +++ /dev/null @@ -1,7 +0,0 @@ -import java.io.File -import kotlin.random.Random - -fun main() { - var godspeak = File("vocab.txt").bufferedReader().readLines().random() - println(godspeak) -}
\ No newline at end of file diff --git a/src/php.php b/src/php.php deleted file mode 100644 index be6e753..0000000 --- a/src/php.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php - // https://stackoverflow.com/a/5904119 - - $f_contents = file("vocab.txt"); - $line = $f_contents[rand(0, count($f_contents) - 1)]; - echo $line; -?> diff --git a/src/powershell.ps1 b/src/powershell.ps1 deleted file mode 100644 index 9787dcc..0000000 --- a/src/powershell.ps1 +++ /dev/null @@ -1,2 +0,0 @@ -$file = gc ./vocab.txt -Get-Random -InputObject $file
\ No newline at end of file diff --git a/src/python.py b/src/python.py deleted file mode 100644 index 9cf43fa..0000000 --- a/src/python.py +++ /dev/null @@ -1,6 +0,0 @@ -from random import choice - -with open("vocab.txt", "r") as f: - - godspeak = choice(f.read().split()) - print(godspeak) diff --git a/src/r.r b/src/r.r deleted file mode 100644 index bab5fa5..0000000 --- a/src/r.r +++ /dev/null @@ -1,5 +0,0 @@ -lines <- readLines("vocab.txt") - -random_line <- lines[sample(length(lines), 1)] - -print(random_line) diff --git a/src/ruby.rb b/src/ruby.rb deleted file mode 100644 index 42d894c..0000000 --- a/src/ruby.rb +++ /dev/null @@ -1,2 +0,0 @@ -godspeak = File.readlines("vocab.txt").sample -puts godspeak
\ No newline at end of file diff --git a/src/rust.rs b/src/rust.rs deleted file mode 100644 index 9ca5801..0000000 --- a/src/rust.rs +++ /dev/null @@ -1,11 +0,0 @@ -use std::fs::File; -use std::io::{BufRead, BufReader}; - -fn main() { - let file = File::open("src/vocab.txt").unwrap(); - let reader = BufReader::new(file); - let lines = reader.lines().collect::<Result<Vec<_>, _>>().unwrap(); - let random_index = (rand::random::<f64>() * lines.len() as f64) as usize; - let random_line = &lines[random_index]; - println!("{}", random_line); -} diff --git a/src/scala.scala b/src/scala.scala deleted file mode 100644 index 894e787..0000000 --- a/src/scala.scala +++ /dev/null @@ -1,7 +0,0 @@ -object Main extends App { - import scala.io.Source - val fileName = "vocab.txt" - val lines = Source.fromFile(fileName).getLines.toList - val randomLine = lines(scala.util.Random.nextInt(lines.length)) - println(randomLine) -} diff --git a/src/swift.swift b/src/swift.swift deleted file mode 100644 index ccc2b92..0000000 --- a/src/swift.swift +++ /dev/null @@ -1,13 +0,0 @@ -import Foundation - -let filePath = "vocab.txt" -let fileURL = URL(fileURLWithPath: filePath) - -do { - let fileContents = try String(contentsOf: fileURL) - let lines = fileContents.components(separatedBy: "\n") - let randomLine = lines.randomElement()! - print(randomLine) -} catch { - print("Error reading file") -} diff --git a/src/x86ASM.asm b/src/x86ASM.asm new file mode 100644 index 0000000..0dd1db2 --- /dev/null +++ b/src/x86ASM.asm @@ -0,0 +1,89 @@ +section .data + filepath db '../wordLists/vocab.txt', 0 + buf_size equ 1024 + buffer db buf_size dup(0) + newline db 10 + space db ' ' + +section .bss + fd resb 4 + rand_num resd 1 + chosen_words resb 30*32 ; 30 words of 32 bytes each + +section .text + global _start + +_start: + ; Open the file + mov eax, 5 ; sys_open + mov ebx, filepath + mov ecx, 0 ; O_RDONLY + int 0x80 + mov [fd], eax + + ; Read the file + mov eax, 3 ; sys_read + mov ebx, [fd] + mov ecx, buffer + mov edx, buf_size + int 0x80 + + ; Choose 30 random words + mov ecx, buffer + xor edx, edx + mov eax, 0x30 ; ASCII code for '0' + +.random_loop: + cmp edx, 30 + je .print_words + + ; Get a random number + mov eax, 0 ; sys_gettimeofday + mov ebx, 0 + mov ecx, rand_num + int 0x80 + + ; Scale the random number to the range [0, num_words) + mov eax, [rand_num] + mov ebx, eax + imul ebx, 0xFFFFFFFF + mov ecx, dword[num_words] + idiv ecx + + ; Find the corresponding word in the buffer + mov ebx, ecx + xor ecx, ecx + mov cl, byte[newline] + +.find_word: + cmp ebx, 0 + je .random_loop + + cmp byte[ecx], byte[newline] + je .not_found + + dec ebx + inc ecx + jmp .find_word + +.not_found: + inc ecx + lea esi, [chosen_words+edx*32] + mov edi, ecx + mov ecx, 32 + rep movsb + + inc edx + jmp .random_loop + +.print_words: + mov eax, 4 ; sys_write + mov ebx, 1 ; stdout + mov ecx, chosen_words + mov edx, 30*32 + int 0x80 + + ; Exit + mov eax, 1 ; sys_exit + xor ebx, ebx + int 0x80
\ No newline at end of file diff --git a/wordLists/happy.txt b/wordLists/happy.txt new file mode 100644 index 0000000..5db0d49 --- /dev/null +++ b/wordLists/happy.txt @@ -0,0 +1,712 @@ +'kay +African +Angel +BBC +BRB +Bam +Boo +Burp +CIA +California +Catastrophic_Success +China +Church +Cosmos +Dad +Dudly_Doright +FBI +GarryKasparov +Ghost +Give_me_praise +God +God_is_not_mocked +God_smack +Greece +Greek_to_me +Han_shot_first +Hasta +Heaven +Hicc_up +HolySpirit +I'll_ask_nicely +I'll_be_back +I'll_get_right_on_it +I'll_let_you_know +I'll_think_about_it +I'm_God_and_you're_not +I'm_God_who_the_hell_are_you +I'm_beginning_to_wonder +I'm_bored +I'm_busy +I'm_done +I'm_feeling_nice_today +I'm_gonna_smack_someone +I'm_good_you_good +I'm_grieved +I'm_impressed +I'm_in_suspense +I'm_not_dead_yet +I'm_not_sure +I'm_off_today +I'm_on_a_roll +I'm_the_boss +I'm_thrilled +I'm_tired_of_this +IMHO +I_am_not_amused +I_be_like +I_can't_believe_it +I_could_be_wrong +I_could_swear +I_didn't_do_it +I_didn't_see_that +I_don't_care +I_donno +I_forgot +I_give_up +I_got_your_back +I_had_a_crazy_dream +I_hate_when_that_happens +I_have_an_idea +I_just_might +I_love_this +I_love_you +I_made_it_that_way +I_pity_the_fool +I_planned_that +I_quit +I_see_nothing +I_veto_that +I_was_just_thinking +I_was_sleeping +Icarus +If_had_my_druthers +Is_that_so +Is_that_your_final_answer +Isn't_that_special +It's_nice_being_God +It_grieves_me +Ivy_league +Japan +Jedi_mind_trick +Jesus +King_Midas +Knock_you_upside_the_head +LOL +Make_America_Great_Again +Mars +Mission_Accomplished +Mom +Moses +NOT +NeilDeGrasseTyson +Trump +Oh_Hell_No +Oh_really +Okilydokily +One_finger_salute +Oy +Pope +Putin +Pullin_the_dragons_tail +ROFLMAO +Russia +Shakespeare +Shalom +Shhh +StephenHawking +SupremerCourt +Terry +That's_gonna_leave_a_mark +That's_my_favorite +The_good_stuff +This_is_confusing +Varoom +Vegas +Venus +Watch_this +What +What_I_want +What_are_you_doing_Dave +WooHoo +Wow +Yawn +Yes_you_are +Yo +You_can_count_on_that +You_da_man +You_fix_it +You_get_what_you_pray_for +You_know +Zap +Zzzzzzzz +a_flag_on_that_play +a_likely_story +a_screw_loose +abnormal +absetively_posilutely +absolutely +act +adjusted_for_inflation +adultery +after_a_break +ahh +ahh_thats_much_better +air_head +and_the_award_goes_to +and_then_what +angel +anger +application +are_you_deaf +are_you_feeling_lucky +are_you_insane +are_you_sure +arent_you_clever +arrogant +as_a_matter_of_fact +astounding +astronomical +astrophysics +atheist +atrocious +au_revoir +awesome +awful +ba_ha +bad +bad_ol_puddytat +baffling +bank +basically +basket_case +bastard +battle +be_happy +be_quiet_bird +beam_me_up +because_I_said_so +beep_beep +begs_the_question +bickering +big_fish +biggot +birds +bizarre +blessing +boink +boss +break_some_woopass_on_you +bring_it_on +bummer +busybody +but_of_course +by_the_way +bye +can_you_hear_me_now +car +catastrophe +caution +chaos +charged +charity +check_this_out +cheerful +chess +chill +chill_out +choose_one +chump_change +church +class__class__shutup +clever +climate +close_your_eyes +come_and_get_me +comedy +commanded +completely +computers +conservative +cosmetics +could_it_be___Satan +couldn't_be_better +couldnt_possibly +courage +cowardice +cracks_me_up +crash_and_burn +crazy +cursing +dance +dang_it +daunting +dean_scream +debt +delicious +delightful +depressing +desert +didn't_I_say_that +dignity +do_I_have_to +do_it +do_not_disturb +do_over +do_you_get_a_cookie +do_you_have_a_problem +do_you_know_what_time_it_is +do_you_like_it +do_you_want_another +doh +don't_count_on_it +don't_even_think_about_it +don't_have_a_cow +don't_mention_it +don't_push_it +don't_worry +downer +drama +driving +duck_the_shoe +dude_such_a_scoffer +earnest +economy +eh +ehh_a_wise_guy +ehheh_that's_all_folks +employee +employer +end +endeared +endeavor +endure +energy +enough +enough_said +envy +epic_fail +et_tu +everything's_a_okay +evolution +exorbitant +experts +exports +fabulous +face_palm +failure_is_not_an_option +failure_to_communicate +fake +fancy +far_out_man +fer_sure +fight +figuratively +food +fool +fortitude +foul +freak +frown +fun +funny +furious +gambling +game_changer +game_over +geek +genius +ghastly +ghetto +glam +glorious +gluttony +go_ahead_make_my_day +good +gosh +gross +grumble +guilty +guppy +ha +handyman +hang_in_there +happy +happy_happy_joy_joy +hard_working +harder_than_it_looks +hate +have_fun +he_be_like +heads_I_win_tails_you_lose +heathen +hello +here_now +hey_Mikey_he_likes_it +hey_thats_right +hi +high_five +high_mucky_muck +hilarious +hippy +hit +ho_ho_ho +hobnob +hold_on_a_minute +holer_than_thou +holy_grail +home +homo +honestly +honesty +hooah +hope +hopefully +horrendous +hot_air +hotel +how's_the_weather +how_about +how_about_that +how_about_those_yankees +how_bout_it +how_come +how_could_you +how_do_I_put_this +how_goes_it +how_hard_could_it_be +how_high +huh +humility +humongous +hurts_my_head +husband +hypocrite +ice_cream +if_and_only_if +if_anything_can_go_wrong +illogical +imports +impossible +in_a_galaxy_far_far_away +in_a_perfect_world +in_other_words +in_practice +in_theory +incoming +incredibly +industrious +ingrate +insane +ipod +is_it_just_me_or +it'd_take_a_miracle +it's_hopeless +it's_my_world +it_figures +it_gets_better +it_was_nothing +jealousy +job +jobs +joke +joker +joking +joy +joyful +just_between_us +just_lovely +kick_back +kludge +later +laziness +left_field +let's_roll +let's_see +let_me_count_the_ways +liberal +lift +lighten_up +like_like +listen_buddy +little_buddy +little_fish +look_buddy +look_on_the_brightside +look_out +love +lulz +lust +lying +make_my_day +manufacturing +maybe_I_didn't_make_it_clear +meek +meh +merry_christmas +middle_class +mine +mission_from_God +mocking +money +mundo_stoked +music +my_bad +my_precious +na_na +nasty +naughty +nerd +nevada +never_happy +news_to_me +no_more +no_more_tears +no_news_is_good_news +no_way_dude +no_you_cant +nope +not +not_a_chance_in_hell +not_good +not_in_kansas_anymore +not_in_my_wildest_dreams +not_that_theres_anything_wrong +not_the_sharpest_knife_in_the_drawer +not_too_shabby +now_that_I_think_about_it +now_you_tell_me +nut_job +obviously +off_the_record +oh_come_on +oh_my +oh_no +oh_oh +ohh_thank_you +oil +okay +on_occassion +on_the_otherhand +once_upon_a_time +one_more_time +one_small_step +oops +ordinarily +other +ouch +outrageous +over_the_top +overflow +pardon_the_french +patience +peace +perfect +persistence +pet +petty +phasors_on_stun +pick_me_pick_me +piety +place +play +poor +population +potentially +pow +praise +praying +pride +programming +prosperity +pwned +qed +quit +quit_it +quite +radio +really +recipe +refreshing +relax +repeat_after_me +repent +resume +reverse_engineer +revolution +rich +ridiculous +rip_off +rocket_science +rose_colored_glasses +roses_are_red +rubbish +run_away +saber_rattling +sad +scorning +scum +segway +service_sector +services +sess_me +sex +shist +shucks +silly_human +sing +skills +sky +sloth +slumin +smack_some_sense_into_you +small_talk +smart +smile +smurfs +snap_out_of_it +so_he_sess +so_let_it_be_done +so_let_it_be_written +soap_opera +special_case +spending +spirit +spoiled_brat +sports +spunky +stoked +straighten_up +strip +study +stuff +stunning +super_computer +surprise_surprise +take_the_day_off +take_your_pick +talk_to_my_lawyer +tattle_tale +taxes +test_pilot +thank_you_very_much +that's_all_folks +that's_for_me_to_know +that's_much_better +that's_no_fun +that's_your_opinion +thats_just_wrong +thats_laughable +thats_right +the +the_enquirer +theft +theres_no_place_like_home +these_cans_are_defective +think_you_could_do_better +this_might_end_badly +threads +tiffanies +to_infinity_and_beyond +tomorrow +tree_hugger +try_again +uh_huh +umm +umm_the_other_answer +umm_what_now +unemployment +unsung_hero +vengeance +vengeful +vermin +vice +virtue +voodoo +vote +walking +wanna_bet +wastoid +watch_it_buddy +wazz_up_with_that +we_ve_already_got_one +well_I_never +well_golly +well_obviously +whale +what's_it_to_you +what's_the_plan +what's_up +what_a_mess +what_a_nightmare +what_do_you_expect +what_do_you_want +what_have_you_done_for_me_lately +what_luck +what_part_of_God_do_you_not_understand +what_planet_are_you_from +what_the_heck +what_was_I_thinking +what_would_Jesus_do +whatcha_talkin'_'bout +whazza_matter_for_you +when_hell_freezes_over +where's_the_love +whiner +white_trash +who's_to_say +who_are_you_to_judge +whoop_there_it_is +why_didn'_you_tell_me +why_do_I_put_up_with_this +why_is_it +wishful_thinking +won't_you_be_my_neighbor +wonderbread +wonderful +woot +wot +wrath +yada_yada_yada +yeah +yep +yikes +you'll_see +you're_fired +you're_in_big_trouble +you're_lucky +you're_no_fun +you're_not_all_there_are_you +you're_nuts +you're_out_of_your_mind +you're_so_screwed +you're_welcome +you're_wonderful +you_are_my_sunshine +you_better_not +you_do_it +you_don't_like_it +you_don't_say +you_hoser +you_know_a_better_God +you_never_know +you_owe_me +you_see_the_light +you_should_be_so_lucky +you_shouldn't_have +you_talkin'_to_me +you_think_I'm_joking +you_think_you_could_do_better +yuck +zoot +red_fang +rum_bitty_di +I_m_prettier_than_this_man +This_cant_be_william_wallace +got_the_life +king_nun +king_of_mars +an_Irishman_is_forced_to_talk_to_God +you_couldnt_navigate_yer_way_circleK +its_trivial_obviously +rufus!i
\ No newline at end of file diff --git a/src/vocab.txt b/wordLists/vocab.txt index 4d4d42b..9d6860e 100644 --- a/src/vocab.txt +++ b/wordLists/vocab.txt @@ -7566,4 +7566,4 @@ youths zeal zealous zealously -zip +zip
\ No newline at end of file |