Skip to content

Instantly share code, notes, and snippets.

@nskvortsov
nskvortsov / gist:1451007
Created December 9, 2011 10:22
Lottery
function try_to_win() {
// assume random is in [0,1]
int i = round(random() * 100)
if (i == 100) {
return UBELIEVABLE_JACKPOT // May never happen
} else if (i > 95) {
return BIGGEST_PRIZE // about once in 20 rolls
} else if (i > 75) {
senderThread = new Thread() {
run () {
while (!runSender) {
int id = nextIdFromQueue();
if (id == null) {
Thread.currentThread().sleep(50)
continue;
} else {
byte[] data = RMS.read(id);
RMS.remove(id); // данные прочитали, убили из хранилища.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(void) {
int status, w;
pid_t pid;