Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/wengchaoxi/go-lottery

A Go language program for fair random drawing based on future events. 基于未来事件进行公正随机抽奖的 Go 语言程序。
https://github.com/wengchaoxi/go-lottery

blockchain btc go lottery random

Last synced: 22 days ago
JSON representation

A Go language program for fair random drawing based on future events. 基于未来事件进行公正随机抽奖的 Go 语言程序。

Awesome Lists containing this project

README

        

# Go Lottery

**English** | [简体中文](./README.zh-CN.md)

## Overview

Go Lottery determines winners by hashing the unique identifiers of all participants and comparing them to the hash of an unpredictable and publicly verifiable event (such as the hash of a BTC block at a future point in time). The participant whose hash value is closest to that of the event is declared the winner.

Advantages:

- True Randomness: The lottery results are tied to an unpredictable future event (e.g., the hash of a future BTC block), ensuring true randomness.

- Public Verification: As the random event (e.g., the hash of a future BTC block) is publicly available, the fairness of the results can be monitored and verified by the public.

## Usage

```go
package main

import "github.com/wengchaoxi/go-lottery/lottery"

func main() {
lot := lottery.NewLottery()

timeStr := "2024/01/01-00:00:00"
randomEvent := lottery.BTCBlockInfo(timeStr, "2006/01/02-15:04:05")
lot.SetRandomEvent(randomEvent)

participants := []string{"Alice", "Bob", "Charlie", "Dave"}
lot.Run(participants)
lot.PrintWinner()
}
```

## Attribution

This program design was originally inspired from the work at [peng-zhihui/BilibiliLottery](https://github.com/peng-zhihui/BilibiliLottery)