本文目录一览:
- 1、用JAVA编写一个福利彩票机选模拟器,使用随机数方法
- 2、C语言 实现模拟彩票的程序设计:随机产生7个数字(用C语言随机函数产生,[1,33]区间,七个数互
- 3、跪求用VB程序设计《彩票选号小助手》小程序,,跪求帮忙,,,,感激不尽
用JAVA编写一个福利彩票机选模拟器,使用随机数方法
自己写的,不懂可以问我
import java.util.Random;
import java.awt.*;
import java.awt.event.*;
public class shuangSeQiu implements ActionListener{
int i,k;
static int rm,rr;
int [] a = new int [33];
Frame f = new Frame("双色球随机数");
TextField tf = new TextField();
Random rd = new Random();
public shuangSeQiu()
{
for(i=0;i33;i++)
{
a[i] = i;
}
f.setLayout(new BorderLayout());
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void init()
{
tf.addActionListener(this);
Button b = new Button("开始");
b.addActionListener(this);
f.add(tf,"North");
f.add(b);
f.setSize(300,300);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("开始"))
//tf.setText(""+(rd.nextInt(33)+1)+" "+(rd.nextInt(33)+1)+" "+(rd.nextInt(33)+1)+" "+(rd.nextInt(33)+1)+" "+(rd.nextInt(33)+1)+" "+(rd.nextInt(33)+1)+" 蓝色球号码:"+(rd.nextInt(15)+1));
{
/*rr = new Random().nextInt(33);
rm = new Random().nextInt(33);*/
for(i=0;i33;i++)
{
rr = new Random().nextInt(33);
rm = new Random().nextInt(33);
System.out.print(rr+" ");
k=a[rm];
a[rm]=a[rr];
a[rr]=k;
}
tf.setText("红色球号码:"+(a[0]+1)+" "+(a[1]+1)+" "+(a[2]+1)+" "+(a[3]+1)+" "+(a[4]+1)+" "+(a[5]+1)+" 蓝色球号码:"+(rd.nextInt(15)+1));
}
}
public static void main(String[] args)//throws Exception
{
new shuangSeQiu().init();
}
}
C语言 实现模拟彩票的程序设计:随机产生7个数字(用C语言随机函数产生,[1,33]区间,七个数互
使用结构体链表模拟彩票的摇奖机,来保证每次随机都是不同的数字。
数组也可以模拟,但是删除元素比较麻烦,用链表更快捷。
定义数组指针,动态分配内存。
#include stdio.h
#include stdlib.h
#include time.h
typedef struct List {
int number;
struct List*next;
} ArrayList;
ArrayList*createList(int);//创建链表,参数是链表的节点数
void freeList(ArrayList*);//循环释放所有节点的内存
int deleteNode(ArrayList*,int);//删除节点,返回节点的数据
main() {
//动态创建内存
int*numbers=(int*)calloc(7,sizeof(int));
int*inNumbers=(int*)calloc(7,sizeof(int));
//动态创建数组链表存放1-33个编号
ArrayList*balls= createList(33);
int i;
srand((unsigned)time(NULL));
printf("请输入7个不同的数字(1-33):\n");
for(i=0; i7; i++) {
*(numbers+i)=deleteNode(balls,rand()%(33-i));
scanf("%d",inNumbers+i);
}
printf("随机产生的7个数字是:\n");
for(i=0; i7; i++) {
printf("%d ",*(numbers+i));
}
printf("\n相同的数字:\n");
//查找
int j;
for(i=0; i7; i++) {
for(j=0; j7; j++) {
if(*(numbers+i)==*(inNumbers+j)) {
printf("%d ",*(numbers+i));
break;
}
}
}
//释放内存
free(numbers);
free(inNumbers);
freeList(balls);
}
ArrayList*createList(int n) {
ArrayList*head=NULL,*end=NULL,*node=NULL;
end=head=(ArrayList*)malloc(sizeof(ArrayList));//head在删除和插入节点时有用。 不能删除head,也不能插入到head前面
int i;
for(i=1; i=n; i++) {
node=(ArrayList*)malloc(sizeof(ArrayList));
node-number=i;
end-next=node;
end=node;
}
end-next=NULL;
return head;
}
void freeList(ArrayList*head) {
ArrayList*node=head;
while(head!=NULL) {
head=head-next;
free(node);
node=head;
}
}
int deleteNode(ArrayList*head,int index) { //index节点索引(0-32),返回被删除的球的编号
ArrayList*node=head-next,*temp=head;
int i=0,number;
while(iindexnode!=NULL) {
temp=node;
node=node-next;
i++;
}
if(node!=NULL) {
number=node-number;
temp-next=node-next;
free(node);
}
return number;
}
运行结果
跪求用VB程序设计《彩票选号小助手》小程序,,跪求帮忙,,,,感激不尽
选号的网页多得很,不知你为何要做这个玩意,还不如直接用excel随机选。
先留个脚印