礼物抽奖的编程可以通过多种编程语言实现,以下是几种常见编程语言的示例代码:
Python 示例
```python
import random
def lottery(participants):
the_rest = participants.copy()
choose_one = {}
num = len(participants)
for i in range(num):
participant = participants[i]
lucky_person = ''
while lucky_person == '' or lucky_person == participant:
lucky_person = random.choice(the_rest)
choose_one[participant] = lucky_person
the_rest.remove(lucky_person)
return choose_one
participants = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
result = lottery(participants)
print(result)
```
Java 示例
```java
import java.util.Random;
public class LotteryProgram {
public static void main(String[] args) {
String[] prizes = {"一等奖", "二等奖", "三等奖", "安慰奖"};
Random random = new Random();
int index = random.nextInt(prizes.length);
System.out.println("恭喜您抽中了: " + prizes[index]);
}
}
```
JavaScript 示例(使用 HTML 和 JavaScript)
```html
抽奖程序