initial commit
This commit is contained in:
commit
1fa8fcec64
3 changed files with 36 additions and 0 deletions
11
README.md
Normal file
11
README.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
# Fortune
|
||||
|
||||
A no-nonsense, user-extensible `fortune-mod` replacement.
|
||||
|
||||
## Goals
|
||||
|
||||
- Sensible: I'm fed up with fortunes about men hating their wives.
|
||||
- Straightforward: No weird formats. Plain text with `\n` escape sequences.
|
||||
|
||||
|
1
data/.gitkeep
Normal file
1
data/.gitkeep
Normal file
|
@ -0,0 +1 @@
|
|||
|
24
src/Program.cs
Normal file
24
src/Program.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
var resourcePath = "/usr/share/fortune-cs/";
|
||||
if(!Directory.Exists(resourcePath)) {
|
||||
Console.WriteLine("fortune-cs: directory '/usr/share/fortune-cs/' does not exist");
|
||||
return 1;
|
||||
}
|
||||
|
||||
var files = Directory.GetFiles(resourcePath, "*.txt");
|
||||
|
||||
var prng = RandomNumberGenerator.Create();
|
||||
|
||||
var file = files[RandomNumberGenerator.GetInt32(files.Length)];
|
||||
var lines = File.ReadAllLines(file);
|
||||
var line = lines[RandomNumberGenerator.GetInt32(lines.Length)];
|
||||
|
||||
prng.Dispose();
|
||||
|
||||
Console.WriteLine(line);
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in a new issue