Skip to content

Instantly share code, notes, and snippets.

@oupo
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oupo/cd7d7575ee9b7a8183e0 to your computer and use it in GitHub Desktop.
Save oupo/cd7d7575ee9b7a8183e0 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Text;
using ICalculator = global::PlusleSeedCalculator.Library.ICalculator;
using IRandomK = global::PlusleSeedCalculator.Library.IRandomK;
using IRandomS = global::PlusleSeedCalculator.Library.IRandomS;
using Result = global::PlusleSeedCalculator.Library.Result;
using ResultData = global::PlusleSeedCalculator.Library.ResultData;
namespace Io.Github.Oupo.Plugin.RafflePlugin
{
public class RaffleCalculator : PlusleSeedCalculator.Library.ICalculator
{
public RaffleCalculator(int min, int max, int days)
{
_min = min;
_max = max;
_days = days;
}
private readonly int _min, _max, _days;
public bool Calculate(PlusleSeedCalculator.Library.IRandomK randK, PlusleSeedCalculator.Library.IRandomS randS, out PlusleSeedCalculator.Library.Result result)
{
int value;
uint raffleseed;
bool ok = JudgeSeed(randS.NextSeed(), out value, out raffleseed);
List<ResultData> list = new List<ResultData>();
list.Add(new ResultData(raffleseed.ToString("X8")));
list.Add(new ResultData(value.ToString()));
result = new Result(list);
return ok;
}
private bool JudgeSeed(ulong seed, out int value, out uint raffleseed)
{
// 通常の(A,B)を6回合成したもの
const ulong A = 0x6d850eda12fc7e49;
const ulong B = 0x0c45453a2b8a2726;
raffleseed = (uint)(seed >> 32);
ulong raffleseed2 = raffleseed;
for (int i = 0; i < _days; i++)
{
raffleseed2 = (raffleseed2 * 0x5d583d6d6c078979u + 0x26a693) >> 32;
}
value = (int)((((A*raffleseed2+B) >> 32) * 0xffff) >> 32);
return raffleseed != 0 && _min <= value && value < _max;
}
public PlusleSeedCalculator.Library.Result Header
{
get
{
List<ResultData> list = new List<ResultData>();
list.Add(new ResultData("くじseed"));
list.Add(new ResultData("くじ乱数値"));
return new Result(list);
}
}
public string HtmlHeaderTitle
{
get { return "くじ検索"; }
}
public string HtmlPageTitle
{
get { return "くじ検索結果"; }
}
public string HtmlStyleSheet
{
get { return string.Empty; }
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using ICalculator = global::PlusleSeedCalculator.Library.ICalculator;
using IPlugin = global::PlusleSeedCalculator.Library.IPlugin;
using IUtil = global::PlusleSeedCalculator.Library.IUtil;
namespace Io.Github.Oupo.Plugin.RafflePlugin
{
public class RafflePlugin : PlusleSeedCalculator.Library.IPlugin
{
private readonly RafflePluginControl _pluginControl = new RafflePluginControl();
public void FinalizePlugin(PlusleSeedCalculator.Library.IUtil util)
{
}
public PlusleSeedCalculator.Library.ICalculator GetCalculator()
{
return new RaffleCalculator(_pluginControl.Min, _pluginControl.Max, _pluginControl.Days);
}
public void InitializePlugin(PlusleSeedCalculator.Library.IUtil util)
{
}
public System.Windows.Forms.UserControl PluginControl
{
get { return _pluginControl; }
}
public string PluginName
{
get { return "くじ"; }
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Io.Github.Oupo.Plugin.RafflePlugin
{
public partial class RafflePluginControl : UserControl
{
public RafflePluginControl()
{
InitializeComponent();
}
public int Min
{
get {
int val;
return int.TryParse(min.Text, out val) ? val : 0;
}
}
public int Max
{
get {
int val;
return int.TryParse(max.Text, out val) ? val : 0;
}
}
public int Days
{ get { return (int)days.Value; } }
private void button1_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void label1_Click_1(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
}
}
namespace Io.Github.Oupo.Plugin.RafflePlugin
{
partial class RafflePluginControl
{
/// <summary>
/// 必要なデザイナー変数です。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 使用中のリソースをすべてクリーンアップします。
/// </summary>
/// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region コンポーネント デザイナーで生成されたコード
/// <summary>
/// デザイナー サポートに必要なメソッドです。このメソッドの内容を
/// コード エディターで変更しないでください。
/// </summary>
private void InitializeComponent()
{
this.label2 = new System.Windows.Forms.Label();
this.min = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.max = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.days = new System.Windows.Forms.NumericUpDown();
this.label4 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.days)).BeginInit();
this.SuspendLayout();
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(13, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(115, 12);
this.label2.TabIndex = 1;
this.label2.Text = "景品を決める値の範囲";
this.label2.Click += new System.EventHandler(this.label2_Click);
//
// min
//
this.min.Location = new System.Drawing.Point(134, 57);
this.min.Name = "min";
this.min.Size = new System.Drawing.Size(89, 19);
this.min.TabIndex = 2;
this.min.Text = "0";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(229, 64);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(29, 12);
this.label1.TabIndex = 3;
this.label1.Text = "以上";
this.label1.Click += new System.EventHandler(this.label1_Click_1);
//
// max
//
this.max.Location = new System.Drawing.Point(264, 57);
this.max.Name = "max";
this.max.Size = new System.Drawing.Size(89, 19);
this.max.TabIndex = 4;
this.max.Text = "4";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(359, 64);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(29, 12);
this.label3.TabIndex = 5;
this.label3.Text = "未満";
//
// days
//
this.days.Location = new System.Drawing.Point(15, 18);
this.days.Name = "days";
this.days.Size = new System.Drawing.Size(63, 19);
this.days.TabIndex = 6;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(84, 20);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(54, 12);
this.label4.TabIndex = 7;
this.label4.Text = "日後のくじ";
this.label4.Click += new System.EventHandler(this.label4_Click);
//
// RafflePluginControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.label4);
this.Controls.Add(this.days);
this.Controls.Add(this.label3);
this.Controls.Add(this.max);
this.Controls.Add(this.label1);
this.Controls.Add(this.min);
this.Controls.Add(this.label2);
this.Name = "RafflePluginControl";
this.Size = new System.Drawing.Size(415, 217);
((System.ComponentModel.ISupportInitialize)(this.days)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox min;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox max;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.NumericUpDown days;
private System.Windows.Forms.Label label4;
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment