Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfur 'Felt her' Deltur committed Aug 18, 2015
1 parent be9909b commit cb449a8
Show file tree
Hide file tree
Showing 14 changed files with 972 additions and 0 deletions.
20 changes: 20 additions & 0 deletions DUMB.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DUMB", "DUMB\DUMB.csproj", "{B9ECD333-FBD9-48D8-9E09-1913C0D796FE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B9ECD333-FBD9-48D8-9E09-1913C0D796FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B9ECD333-FBD9-48D8-9E09-1913C0D796FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B9ECD333-FBD9-48D8-9E09-1913C0D796FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B9ECD333-FBD9-48D8-9E09-1913C0D796FE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
82 changes: 82 additions & 0 deletions DUMB/DUMB.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B9ECD333-FBD9-48D8-9E09-1913C0D796FE}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DUMB</RootNamespace>
<AssemblyName>DUMB</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ISAAC.cs" />
<Compile Include="Main.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Main.Designer.cs">
<DependentUpon>Main.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Main.resx">
<DependentUpon>Main.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
201 changes: 201 additions & 0 deletions DUMB/ISAAC.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace DUMB
{
/**
------------------------------------------------------------------------------
Rand.java: By Bob Jenkins. My random number generator, ISAAC.
rand.init() -- initialize
rand.val() -- get a random value
MODIFIED:
960327: Creation (addition of randinit, really)
970719: use context, not global variables, for internal state
980224: Translate to Java
------------------------------------------------------------------------------
*/
public class ISAAC
{
public const int SIZEL = 9; /* log of size of rsl[] and mem[] */
public const int SIZE = 1 << SIZEL; /* size of rsl[] and mem[] */
public const int MASK = (SIZE - 1) << 2; /* for pseudorandom lookup */
public int count; /* count through the results in rsl[] */
public int[] rsl; /* the results given to the user */
public int[] mem; /* the internal state */
private int a; /* accumulator */
private int b; /* the last result */
private int c; /* counter, guarantees cycle is at least 2^^40 */


/* no seed, equivalent to randinit(ctx,FALSE) in C */
public ISAAC()
{
mem = new int[SIZE];
rsl = new int[SIZE];
Init(false);
}

/* equivalent to randinit(ctx, TRUE) after putting seed in randctx in C */
public ISAAC(int[] seed)
{
mem = new int[SIZE];
rsl = new int[SIZE];
for (int i = 0; i < seed.Length; ++i)
{
rsl[i] = seed[i];
}
Init(true);
}


/* Generate 256 results. This is a fast (not small) implementation. */
public /*final*/ void Isaac()
{
int i, j, x, y;

b += ++c;
for (i = 0, j = SIZE / 2; i < SIZE / 2; )
{
x = mem[i];
a ^= a << 13;
a += mem[j++];
mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[((y >> SIZEL) & MASK) >> 2] + x;

x = mem[i];
a ^= (int)((uint)a >> 6);
a += mem[j++];
mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[((y >> SIZEL) & MASK) >> 2] + x;

x = mem[i];
a ^= a << 2;
a += mem[j++];
mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[((y >> SIZEL) & MASK) >> 2] + x;

x = mem[i];
a ^= (int)((uint)a >> 16);
a += mem[j++];
mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[((y >> SIZEL) & MASK) >> 2] + x;
}

for (j = 0; j < SIZE / 2; )
{
x = mem[i];
a ^= a << 13;
a += mem[j++];
mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[((y >> SIZEL) & MASK) >> 2] + x;

x = mem[i];
a ^= (int)((uint)a >> 6);
a += mem[j++];
mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[((y >> SIZEL) & MASK) >> 2] + x;

x = mem[i];
a ^= a << 2;
a += mem[j++];
mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[((y >> SIZEL) & MASK) >> 2] + x;

x = mem[i];
a ^= (int)((uint)a >> 16);
a += mem[j++];
mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[((y >> SIZEL) & MASK) >> 2] + x;
}
}


/* initialize, or reinitialize, this instance of rand */
public /*final*/ void Init(bool flag)
{
int i;
int a, b, c, d, e, f, g, h;
a = b = c = d = e = f = g = h = unchecked((int)0x9e3779b9); /* the golden ratio */

for (i = 0; i < 4; ++i)
{
a ^= b << 11; d += a; b += c;
b ^= (int)((uint)c >> 2); e += b; c += d;
c ^= d << 8; f += c; d += e;
d ^= (int)((uint)e >> 16); g += d; e += f;
e ^= f << 10; h += e; f += g;
f ^= (int)((uint)g >> 4); a += f; g += h;
g ^= h << 8; b += g; h += a;
h ^= (int)((uint)a >> 9); c += h; a += b;
}

for (i = 0; i < SIZE; i += 8)
{ /* fill in mem[] with messy stuff */
if (flag)
{
a += rsl[i]; b += rsl[i + 1]; c += rsl[i + 2]; d += rsl[i + 3];
e += rsl[i + 4]; f += rsl[i + 5]; g += rsl[i + 6]; h += rsl[i + 7];
}
a ^= b << 11; d += a; b += c;
b ^= (int)((uint)c >> 2); e += b; c += d;
c ^= d << 8; f += c; d += e;
d ^= (int)((uint)e >> 16); g += d; e += f;
e ^= f << 10; h += e; f += g;
f ^= (int)((uint)g >> 4); a += f; g += h;
g ^= h << 8; b += g; h += a;
h ^= (int)((uint)a >> 9); c += h; a += b;
mem[i] = a; mem[i + 1] = b; mem[i + 2] = c; mem[i + 3] = d;
mem[i + 4] = e; mem[i + 5] = f; mem[i + 6] = g; mem[i + 7] = h;
}

if (flag)
{ /* second pass makes all of seed affect all of mem */
for (i = 0; i < SIZE; i += 8)
{
a += mem[i]; b += mem[i + 1]; c += mem[i + 2]; d += mem[i + 3];
e += mem[i + 4]; f += mem[i + 5]; g += mem[i + 6]; h += mem[i + 7];
a ^= b << 11; d += a; b += c;
b ^= (int)((uint)c >> 2); e += b; c += d;
c ^= d << 8; f += c; d += e;
d ^= (int)((uint)e >> 16); g += d; e += f;
e ^= f << 10; h += e; f += g;
f ^= (int)((uint)g >> 4); a += f; g += h;
g ^= h << 8; b += g; h += a;
h ^= (int)((uint)a >> 9); c += h; a += b;
mem[i] = a; mem[i + 1] = b; mem[i + 2] = c; mem[i + 3] = d;
mem[i + 4] = e; mem[i + 5] = f; mem[i + 6] = g; mem[i + 7] = h;
}
}

Isaac();
count = SIZE;
}


/* Call rand.val() to get a random value */
public /*final*/ int val()
{
if (0 == count--)
{
Isaac();
count = SIZE - 1;
}
return rsl[count];
}

//public static void main(String[] args) {
// int[] seed = new int[256];
// Rand x = new Rand(seed);
// for (int i=0; i<2; ++i) {
// x.Isaac();
// for (int j=0; j<Rand.SIZE; ++j) {
// //String z = Integer.toHexString(x.rsl[j]);
// //while (z.length() < 8) z = "0"+z;
// Console.WriteLine("{0:X8}", x.rsl[j]);
// if ((j&7)==7) Console.WriteLine("");
// }
// }
//}
}
}
Loading

0 comments on commit cb449a8

Please sign in to comment.