急求:一个11选5的彩票算法!!!!

lucyskys 2010-12-29 04:01:01
如题,需求一个11选5的彩票算法,最好能随机选出数组的。。。谢谢!!!!
...全文
840 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
TONYBLARED 2011-11-23
  • 打赏
  • 举报
回复
我还真拿出来的结果去买过,还真中过!
TONYBLARED 2011-11-23
  • 打赏
  • 举报
回复
package com.dell.misc;

public class Conica {
public static void pr(Object obj) {
System.out.print(obj);
}

public static void pl(Object obj) {
System.out.println(obj);
}

public static void pl() {
System.out.println();
}

public static void pl(String[] arr) {
for(int i = 0; i < arr.length; i++) {
System.out.println("i=" + i + ", value=" + arr[i]);
}
}

public static void pl(int[] arr) {
for(int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + "\t");
}
}
}
TONYBLARED 2011-11-23
  • 打赏
  • 举报
回复
package com.dell.lottery;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

import com.dell.misc.Conica;

public class LotteryMain {
int times = 1;
int[] choice;

public static void main(String[] args) {
LotteryMain instance = new LotteryMain();
instance.init();
instance.roll();
instance.calc();
}

public void init() {
choice = new int[12];

Conica.pr("Index for sample size:");
Scanner scn = new Scanner(System.in);
int input = scn.nextInt();
if(input != 0) {
times = input * 1000;
}

Conica.pl("Sample size:" + times);
}

public void roll() {
for(int i=0; i < times; i++) {
HashMap map = new HashMap();
int size = map.size();
while(size < 5) {
Random random = new Random();
int randomInt = random.nextInt(11) + 1;
Object obj = map.get(randomInt);
if(obj == null) {
// Conica.pr(randomInt + "\t");
map.put(randomInt, randomInt);
choice[randomInt]++;
}

size = map.size();
}
// Conica.pl();
}
}

public void calc() {
int[] arr = choice;

List list = new ArrayList();
for(int i=1; i < arr.length; i++) {
list.add(arr[i]);
}

Conica.pl(list);

int figure = 3;
int[] maxArr = new int[figure];

for(int k = 0; k < figure; k++) {
int index = 0;
int max = arr[index];
for(int i=1; i < arr.length; i++) {
int temp = arr[i];
if(temp > max) {
max = temp;
index = i;
}
}

maxArr[k] = index;
choice[index] = 0;
}

Conica.pl("Following could be your luck number tonight:");

for(int i=0; i<maxArr.length; i++) {
Conica.pr(maxArr[i] + " ");
}
Conica.pl();
}
}
子夜__ 2010-12-31
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 lucyskys 的回复:]

谢谢楼上的。。。
[/Quote]
呵呵
lucyskys 2010-12-31
  • 打赏
  • 举报
回复
谢谢楼上的。。。
子夜__ 2010-12-29
  • 打赏
  • 举报
回复
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace TestImg
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int[] c = RandomNumbers(5, 1, 11);
if (c.Length != 0)
{
for (int i = 0; i < c.Length; i++)
{
Response.Write(c[i].ToString() + "<br/>");
}
}
else
{
Response.Write("Error");
}


}

/// <summary>
/// 随机数
/// </summary>
/// <param name="ACount">个数</param>
/// <param name="AMinValue">最小值</param>
/// <param name="AMaxValue">最大值</param>
/// <returns></returns>
public static int[] RandomNumbers(int ACount, int AMinValue, int AMaxValue)
{
if (ACount <= 0) return null;
if (AMaxValue < AMinValue)
AMinValue = AMaxValue | (AMaxValue = AMinValue) & 0;
if (ACount > AMaxValue - AMinValue + 1) return null;
List<int> vValues = new List<int>();
for (int i = AMinValue; i <= AMaxValue; i++)
vValues.Add(i);
int[] Result = new int[ACount];
Random vRandom = new Random();
for (int i = 0; i < ACount; i++)
{
int j = vRandom.Next(vValues.Count);
Result[i] = vValues[j];
vValues.RemoveAt(j);
}
return Result;
}

}
}
gongsun 2010-12-29
  • 打赏
  • 举报
回复
你GG : 抽奖算法!!!
刀枪blue 2010-12-29
  • 打赏
  • 举报
回复
坐等sf的算法
IHandler 2010-12-29
  • 打赏
  • 举报
回复
参考

/// <summary>
/// 从1到n中任意选取不重复的10个随机数
/// </summary>
/// <returns></returns>
private List<int> GenerateNumber()
{
//用于保存返回结果
List<int> result = new List<int>(10);
Random random = new Random();
int index = 0;
int value = 0;
for (int i = 1; i <= 10; i++)
{
//从[0,container.Count)中取一个随机值,保证这个值不会超过container的元素个数
index = random.Next(0, container.Count);//谢谢热心朋友指出这里的错误
//以随机生成的值作为索引取container中的值
value = container[index];
//将随机取得值的放到结果集合中
result.Add(value);
//从容器集合中删除这个值,这样会导致container.Count发生变化
container.RemoveAt(index);
}
//result.Sort();排序
return result;
}
子夜__ 2010-12-29
  • 打赏
  • 举报
回复
==我来写一个。哈哈

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧